我試圖做到以下幾點:C++開關:case <some constant> - 這是允許的嗎?
switch(moveDirection){
case MOVE_DIRECTION_UP:
//do something
break;
}
哪裏MOVE_DIRECTION_UP是這樣的:
const unsigned char MOVE_DIRECTION_UP = 0x0;
編譯器給出了錯誤:MOVE_DIRECTION_UP不能出現在常量表達式
當然這應該是允許,因爲如果我用0x0替換MOVE_DIRECTION_UP,它編譯得很好。
任何幫助表示讚賞,謝謝!
哪個編譯器? g ++不會給我一個錯誤 – asheeshr