1

My code looks like down this:

-(void)touchBegan:(HWPoint *)point {  
    switch (self.states) {  
        case HWDrawState:  
            HWShape *shape = [[HWShapeManager sharedInstance]  addShapeWithType:_shapeClass];  
            break;  
        case HWSelectState:  
            break;  
        case HWDeleteState:  
            break;  
        default:  
            break;  
    }  
}

Why is there a problem with HWShape.... ? I got an error with it:

"error: expected expression before 'HWShape'".

Why is that? Thank you very much for replys.

Svetlozar Angelov
  • 21,214
  • 6
  • 62
  • 67
Tojas
  • 21
  • 4
  • `states` sounds like it is an integer with multiple bit-flags. `case` does only mask if `states` is exactly equal to one of the enum values. – Georg Schölly Nov 30 '09 at 10:37

1 Answers1

6

Enclose the definition in brackets:

case HWDrawState:
{
  HWShape *shape = [[HWShapeManager sharedInstance] addShapeWithType:_shapeClass];
}
break;
case ...
diederikh
  • 25,221
  • 5
  • 36
  • 49
  • 1
    This has been explained there: http://stackoverflow.com/questions/92396/why-cant-variables-be-declared-in-a-switch-statement – mouviciel Nov 30 '09 at 13:47