What are the signs of crosses initialization?

后端 未结 4 1118
谎友^
谎友^ 2020-11-28 03:28

Consider the following code:

#include 
using namespace std;

int main()
{
    int x, y, i;
    cin >> x >> y >> i;
    swit         


        
4条回答
  •  隐瞒了意图╮
    2020-11-28 04:00

    It is possible to transfer into a block, but not in a way that bypasses declarations with initialization. A program that jumps from a point where a local variable with automatic storage duration is not in scope to a point where it is in scope is ill-formed unless the variable has POD type and is declared without an initializer.

    [Example: Code:
    
    void f()
    {
      // ...
      goto lx;    // ill-formed: jump into scope of `a'
      // ...
     ly:
        X a = 1;
      // ...
     lx:
       goto ly;    // ok, jump implies destructor
     // call for `a' followed by construction
     // again immediately following label ly
    }
    
    --end example]
    

    The transfer from the condition of a switch statement to a case label is considered a jump in this respect.

提交回复
热议问题