真心求大家分析下面这个语法错误:: error C2360: initialization of 'tt' is skipped by 'case',附完整代码 - C/C++ / C++ 语言
求大家帮我看下面这个语法错误,分不够 暂时不另外开帖,以后补分
: error C2360: initialization of 'tt' is skipped by 'case' label
: see declaration of 'tt'
error C2360: initialization of 'tt' is skipped by 'case' label
: see declaration of 'tt'
: error C2360: initialization of 'tt' is skipped by 'case' label
: see declaration of 'tt'
: error C2361: initialization of 'tt' is skipped by 'default' label
: see declaration of 'tt'
- 4 error(s), 0 warning(s)
代码: 值得一提的是 我把char* tt=NULL;改成char* tt;就没有错误了,是为什么呢,谢谢好心的你
case 6:
char* tt=NULL;
tt=queryUeData("127.0.0.1",3000);
if ( tt!= NULL)
{
cout<<"queryUeData test succesfull"<<endl;
cout<<tt<<endl;
}
else
{
cout<<"queryUeData test fail"<<endl;
}
Sleep(3000);
//i=4;
break;
[解决办法]
在switch...case...结构中不能在case中定义新变量,除非将定义新变量的case用块{}包住,或者选择将你的新变量在switch之前。
[解决办法]
在case语句里 定义 变量要加花括号
[解决办法]
msdn有下面的说明:
compiler error c2360
initialization of identifier is skipped by case label
the specified identifier initialization can be skipped in a switch statement.
it is illegal to jump past a declaration with an initializer unless the declaration is enclosed in a block.
the scope of the initialized variable lasts until the end of the switch statement unless it is declared in an enclosed block within the switch statement.
the following is an example of this error:
[解决办法]
声明语句放在与case或default相关联的语句中是非法的,除非它放在一个语句快中。
[解决办法]