declare variable in switch?

Possible Duplicate:
Why can't variables be declared in a switch statement?

switch (i){
 case 'i': int i; break; } //it works


switch (i){
 case 'i': int i;i=0; break; } //it also works


switch (i){
 case 'i': int i=0; break; } //it ain't

Dunno the error, but this also works for me in Objective-C (strict superset of C, although I don't believe that 1) and I do this always , even when I simply return something:

switch (i) {

  case 'i': { // <- curly brackets
    int i = 0; break;
  } // <- curly brackets

}

(1 Because a variable can be named id in C but not in Objective-C)

链接地址: http://www.djcxy.com/p/14790.html

上一篇: 初学者C ++:为什么这个switch语句给我一个错误?

下一篇: 在开关中声明变量?