您好,欢迎来到化拓教育网。
搜索
您的当前位置:首页initialization of xxx is skipped by xxx

initialization of xxx is skipped by xxx

来源:化拓教育网
使用case或goto语句时,有时会碰到如下提示:
vc2008:initialization of xxx is skipped by xxx
gcc:crosses initialization of xxx

以case为例:
int main( void )
{
    int a = 2;

    switch (a)
    {
    case 0:
        int b = 0;
        break;
    case 1:
        cout << a << endl;
		break;
    default:
        break;
    }

    return 0;
}

codeblocks(gcc) 编译提示:
In function `int main()':
error: jump to case label
error:   crosses initialization of `int b'
error: jump to case label|
error:   crosses initialization of `int b'
warning: unused variable 'b'
=== Build finished: 4 errors, 1 warnings ===

codeblocks(vc2008) 编译提示:
error C2360: initialization of 'b' is skipped by 'case' label
error C2361: initialization of 'b' is skipped by 'default' label
=== Build finished: 2 errors, 0 warnings ===

问题出在 b 的作用域,b 只在"case 0"的情况下进行了初始化,如果是其他语句就会被跳过去,

改变 b 的作用域就可以了,一般使用{}就可以了

   ...
   case 0:
   {
        int b = 0;
   }
   break;
   ...


转载于:https://www.cnblogs.com/xkxjy/archive/2012/04/07/3672272.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo9.cn 版权所有 赣ICP备2023008801号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务