c++里面的switch-case问题

论坛 期权论坛 脚本     
匿名技术用户   2020-12-29 02:11   474   0

./DBOperator.cpp:87: error: jump to case label
./DBOperator.cpp:84: error: crosses initialization of 'std::string str_timebuf'
./DBOperator.cpp:81: error: crosses initialization of 'char timebuf [128]'


编译下面的代码会报错:

int main()
{
int i;
switch (i)
{
case 3:
int y = 0;
break;
default:
break;
}
}

g++ 编译:
main.cpp: In function `int main()':
main.cpp:11: jump to case label
main.cpp:9: crosses initialization of `int y'

用 gcc 编译:
error: syntax error before "int"

改成这样:
int main()
{
int i;
switch (i)
{
case 3:
int y ;
y = 0;
break;
default:
break;
}
}

gcc 还是没法通过编译。
把 case 部分用 {} 括起来,则都可以通过编译

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP