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

wykqhyjs 2011-03-22 12:36:31
求大家帮我看下面这个语法错误,分不够 暂时不另外开帖,以后补分

: 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;
...全文
511 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
nakedavril 2011-03-22
  • 打赏
  • 举报
回复
在case语句里 定义 变量要加花括号
yarpee 2011-03-22
  • 打赏
  • 举报
回复
在switch...case...结构中不能在case中定义新变量,除非将定义新变量的case用块{}包住,或者选择将你的新变量在switch之前。
wx376752150 2011-03-22
  • 打赏
  • 举报
回复
臭小子,你用goto了吧?嘿嘿,老师强调了好多次,别用goto,哈哈。不过不是绝对的,为了让程序有一个统一的出口,可以考虑用goto,但是仅限于此,也就是说,只能向一个地方跳,不能再跳到别的地方。
解决方法是,在把那些变量的声明定义移动到所有goto之前。希望对你有所帮助。
VC天下 2011-03-22
  • 打赏
  • 举报
回复
加上大括号{}
碎碎念 2011-03-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 yarpee 的回复:]

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

++

编译器的错误提示已经说的很明确了。。。
purewqk 2011-03-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 yarpee 的回复:]
在switch...case...结构中不能在case中定义新变量,除非将定义新变量的case用块{}包住,或者选择将你的新变量在switch之前。
[/Quote]
up...
HayYoung 2011-03-22
  • 打赏
  • 举报
回复
声明语句放在与case或default相关联的语句中是非法的,除非它放在一个语句快中。
  • 打赏
  • 举报
回复
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:

64,682

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧