当前位置: 代码迷 >> 多核软件开发 >> 真心求大家分析下面这个语法异常: error C2360: initialization of 'tt' is skipped by 'case',附完整代码
  详细解决方案

真心求大家分析下面这个语法异常: error C2360: initialization of 'tt' is skipped by 'case',附完整代码

热度:2736   发布时间:2013-02-26 00:00:00.0
真心求大家分析下面这个语法错误:: 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相关联的语句中是非法的,除非它放在一个语句快中。

------解决方案--------------------------------------------------------
探讨
在switch...case...结构中不能在case中定义新变量,除非将定义新变量的case用块{}包住,或者选择将你的新变量在switch之前。

------解决方案--------------------------------------------------------
探讨

在switch...case...结构中不能在case中定义新变量,除非将定义新变量的case用块{}包住,或者选择将你的新变量在switch之前。

------解决方案--------------------------------------------------------
加上大括号{}
------解决方案--------------------------------------------------------
臭小子,你用goto了吧?嘿嘿,老师强调了好多次,别用goto,哈哈。不过不是绝对的,为了让程序有一个统一的出口,可以考虑用goto,但是仅限于此,也就是说,只能向一个地方跳,不能再跳到别的地方。
解决方法是,在把那些变量的声明定义移动到所有goto之前。希望对你有所帮助。
  相关解决方案