tags:

views:

56

answers:

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.

+3  A: 

Enclose the definition in brackets:

case HWDrawState:
{
  HWShape *shape = [[HWShapeManager sharedInstance] addShapeWithType:_shapeClass];
}
break;
case ...
Diederik Hoogenboom
Thank you very much, I'm learning the language now... ;)
Tojas
A reason would be helpful.
Georg
This has been explained there: http://stackoverflow.com/questions/92396/why-cant-variables-be-declared-in-a-switch-statement
mouviciel