error C2630: initialization of * label 错误的原因及解决方法
来源:互联网 发布:千锋教育java怎么样 编辑:程序博客网 时间:2024/05/28 11:28
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:
void func( void ) { 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 } }
在switch语句内定义一个变量的时候,如果不在一个语句块内,它是直到遇到switch的"}"才结束的。
int i = 1;错误,错就错在它是以switch的"}"结束的,此时被case 1:语句跳过,int i = 1不会被初始化。
int j = 1;它是遇到下面的"}"就结束了,因此正确。
int k = 1;它虽然没有在一个语句块中,但它的下一个结束"}"正好就是switch的"}",不会被跳过,因此也正确。
解决方案:1.如果有在case内定义新变量,最好将该条case内的语句加上{}构成语句块,避免出错!
2.在case外部定义变量。
- error C2630: initialization of * label 错误的原因及解决方法
- switch语句“error C2630: initialization of 'k' is skipped by 'case' label”编译错误
- JAVA Error occurred during initialization of VM 错误的解决方法
- Error occurred during initialization of VM 错误的解决方法
- error C2360: initialization of 'hPen' is skipped by 'case' label的解决方法
- Roller源码,Install的时候出现Error occurred during initialization of VM错误时的解决方法
- error: jump to case label 或者 error: crosses initialization of 编译错误
- 启动JBoss时出现“Error occurred during initialization of VM”错误的解决方法
- Java 中“Error occurred during initialization of VM”错误的解决方法
- 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 原因及解决办法
- error: jump to case label与crosses initialization of"xx"编译错误
- ERROR 1093 (HY000) 错误的原因及解决方法!
- error C2470 错误原因及解决方法
- 解决Link 2001错误的一种方法
- MT MTd MD MDd
- GLUT教程
- android.view.WindowManager$BadTokenException: Unable to add window
- 关于Console程序和win32程序的程序入口
- error C2630: initialization of * label 错误的原因及解决方法
- 四元数[转]
- 设计模式之装饰模式
- _error LNK2019
- 避免头文件重复包含
- 常量指针与指针常量的区别
- Bootstr 分页导航
- VS2010 修改全局 include目录
- 自定义OSG窗口大小(设置Osgiewer)