I am trying to do the following:
switch(moveDirection){
case MOVE_DIRECTION_UP:
//do something
break;
}
Where MOVE_DIRECTION_UP is this:
const unsigned char MOVE_DIRECTION_UP = 0x0;
The compiler gives the error: MOVE_DIRECTION_UP cannot appear in constant-expression
Surely this should be allowed, because it compiles fine if I replace MOVE_DIRECTION_UP with 0x0.
Any help is appreciated, thanks!
If you’re working with C++11, you can declare
MOVE_DIRECTION_UPas aconstexpr. The compiler will regard it as a constant value that can be used as a switch label.If you’re not, you may define an enumeration: