C++ 解决"Error: Jump to case label"的问题
2017-07-03 19:43
916 查看
【问题】代码如下
【原因】case 1中声明的变量穿透到case 2中,但是这个变量在case 1中被初始化,但在case 2的作用域内并未初始化
【解决】
switch(foo) { case 1: int i = 42; // i exists all the way to the end of the switch dostuff(i); break; case 2: dostuff(i*2); // i is *also* in scope here, but is not initialized! }
【原因】case 1中声明的变量穿透到case 2中,但是这个变量在case 1中被初始化,但在case 2的作用域内并未初始化
【解决】
switch(foo) { case 1: { int i = 42; // i only exists within the { } dostuff(i); break; } case 2: dostuff(123); // Now you cannot use i accidentally }
相关文章推荐
- 【C/C++】error: jump to case label
- error: jump to case label与crosses initialization of"xx"编译错误
- error: jump to case label,crosses initialization of "xxxxxx"
- 【C/C++】error: jump to case label
- 【C++ 异常】error: jump to case label, crosses initialization
- 关于cannot jump from switch statement to this case label的问题解决
- error: jump to case label
- error: jump to case label
- error: jump to case label \n error: crosses initialization of xxx
- 问题解决:Error -27776: Server "XXX" shut connection during attempt to negotiate SSL session
- vnc Unable to licence server: "XML error 0:0 Error: First Tag not found"问题的解决
- 解决Visual C++ for Linux: -L"~/projects/path_to_lib_folder" 无法设置library search path的问题
- error: jump to case label
- vnc Unable to licence server: "XML error 0:0 Error: First Tag not found"问题的解决
- qt编程中遇到的bug之error: jump to case label [-fpermissive]
- 问题解决:Error -27776: Server "XXX" shut connection during attempt to negotiate SSL session
- switch 语句:error : crosses initialization of 'xxx' and jump to case label [-fpermissive]
- error:jump to case label [-fpermissive]
- symbian “error: jump to case label”
- error:jump to case label error:crosses initialization of