2009-11-30 48 views
1

我的代碼看起來像沿着這條:客觀C開關問題

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

爲什麼會出現與HWShape一個問題....? 我得到了一個錯誤:

"error: expected expression before 'HWShape'".

這是爲什麼?非常感謝您的回覆。

+0

'states'聽起來就像是具有多個比特的標誌的整數。 'case'只在'states'完全等於枚舉值之一時纔會被屏蔽。 – 2009-11-30 10:37:37

回答

6

括在括號內的定義:

case HWDrawState: 
{ 
    HWShape *shape = [[HWShapeManager sharedInstance] addShapeWithType:_shapeClass]; 
} 
break; 
case ... 
+0

非常感謝,我現在正在學習語言...;) – Tojas 2009-11-30 10:32:59

+0

一個理由會有幫助。 – 2009-11-30 10:33:49

+1

這裏已經解釋過了:http://stackoverflow.com/questions/92396/why-cant-variables-be-declared-in-a-switch-statement – mouviciel 2009-11-30 13:47:59