skipped by case
来源:互联网 发布:b站弹幕源码 编辑:程序博客网 时间:2024/05/23 21:26
{
int x;
switch ( x )
{
case 0 :
int i = 1; // error, skipped by case 1
{ int j = 1; } // ok, initialized in enclosing block
case 1 :
int k = 1; // ok, initialization not skipped
}
}
在VC中使用switch语句时遇到“error C2360: initialization of 'k' is skipped by 'case' label”的编译错误。
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:
在switch语句内定义一个变量的时候,如果不在一个语句块内,它是直到遇到switch的"}"才结束的。int i = 1;错误,错就错在它是以switch的"}"结束的,此时被case 1:语句跳过。int j = 1;它是遇到下面的"}"就结束了,因此正确。int k = 1;它虽然没有在一个语句块中,但它的下一个结束"}"正好就是switch的"}",不会被跳过,因此也正确。
所以,如果有在case内定义新变量,最好将该条case内的语句加上{}构成语句块,避免出错。
总之而言:在case里面声明变量要用{}进行作用域限制。
- skipped by case
- error C2360: initialization of 'k' is skipped by 'case' label
- initialization of 'strTemp' is skipped by 'case' label解决办法
- initialization of 'XXX' is skipped by 'case' label
- c++ error initialization of "xxx" is skipped by case label
- error C2360: initialization of 'j' is skipped by 'case' label
- error C2360: initialization of 'hPen' is skipped by 'case' label的解决方法
- initialization of 'XXX' is skipped by 'case' label 原因及解决办法
- initialization of 'XXX' is skipped by 'case' label 原因及解决办法
- initialization of 'XXX' is skipped by 'case' label 原因及解决办法
- initialization of 'XXX' is skipped by 'case' label 原因及解决办法
- initialization of 'XXX' is skipped by 'case' label 原因及解决办法
- initialization of 'XXX' is skipped by 'case' label 原因及解决办法
- switch语句“error C2630: initialization of 'k' is skipped by 'case' label”编译错误
- 在VC中使用switch语句时遇到“error C2360: initialization of 'k' is skipped by 'case' label”的编译错误。
- 在VC中使用switch语句时遇到“error C2360: initialization of 'k' is skipped by 'case' label”的编译错误。
- 在VC中使用switch语句时遇到“error C2360: initialization of 'k' is skipped by 'case' label”的编译错误。
- initialization of * is skipped by 'default' label
- IOS开发之----通讯录访问授权
- 开源镜像站收藏
- error LNK2001: unresolved external symbol GUID_SELF_DEFINE
- 10. 泛型 Part 3 --- 学习笔记
- android中Activity的启动方式
- skipped by case
- 关于各类存储器的一些简单的认识
- Speed Limit - POJ 2017 水题
- jQuery中实现:当文本框输入值,验证值不符合规格,然后是文本框输出原来的值的方法
- 四象限法则
- VNC方式连接树莓派
- 约束规划建模技巧总结---中间变量和全局约束
- jsp中引入脚本文件的路径问题
- view setAnimation 中的动画何时会被调用