Compile Error with: switch, “expected expression before”

后端 未结 3 1718
礼貌的吻别
礼貌的吻别 2020-12-07 18:28

Cut to the chase I have recreated my problem as it is fairly self explanatory.

this complies without error:

switch (n) {
    case 1         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 18:45

    In normal C you'd have to enclose this in brackets in both cases. I suspect this may fix your problem:

    case 1:
    {
        NSLog(@"");
        NSString *aStr;
        break;
    }
    

    See this SO question for more info.

    Another way to get around this problem is to put a statement between the case label and the first declaration as you've done in your working example above. See the comments and Quinn Taylor's answer for more info.

提交回复
热议问题