有这样一段代码:
class NoJump
{
public:
NoJump() {}
};
void FunNoJump(int i)
{
switch (i)
{
case 1:
NoJump aa; //编译出错提示: error C2360: initialization of 'aa' is skipped by 'case' label, see declaration of 'aa'
break;
case 2:
NoJump bb; //编译出错提示:error C2360: initialization of 'bb' is skipped by 'case' label, see declaration of 'bb'
break;
case 3:
break;
}
}
修改后:
void FunNoJump(int i)
{
switch (i)
{
case 1:
{//加上括号
NoJump aa;
}//加上括号
break;
case 2:
{//加上括号
NoJump bb;
}//加上括号
break;
case 3:
break;
}
}
编译通过,没有想明白为什么。。。。