NO!!!!!
If menustate is an enumerated type, then do not try to increment or decrement it by casting it to an int like these bozos are saying. If you want to increment or decrement or do any kind of arithmetic on it, then make menustate an int. enums are not designed for this purpose. Why go through the mess and hassle of turning an enum into an int? Just use an int.
SiCrane''s suggestion of overloading the ++ and -- operators has merit. However, if you want to do more than go to the next or previous states, it will be inadequate.
going through an enumerated type
i also dont see what the big deal is. ive done this samething when making a map editor. just do:
int menustate ;
menustate = NewGame;
menustate++; //now it is HighScore
menustate--; //back to NewGame
Donkey Punch Productions.net
int menustate ;
menustate = NewGame;
menustate++; //now it is HighScore
menustate--; //back to NewGame
Donkey Punch Productions.net
yeah whats the deal with making enums an int thier unisgned ints by default anyhow. Tons of business applications use it in state management.
quote:Original post by SiCrane
I don''t see anything wrong with that code; it should be fine.
The operators return operand +/- 1, but don''t actually change the value of the operand itself. Also, you defined the prefix operators and he is using the postfix operators.
enum Menu {NewGame=0, Highscore=1, Exit=2};Menu & operator++(Menu & m) // ++m{ switch (m) { case NewGame: m = Highscore; case Highscore: m = Exit; case Exit: m = NewGame; } return m;};Menu & operator--(Menu & m) // --m{ switch (m) { case NewGame: m = Exit; case Highscore: m = NewGame; case Exit: m = Highscore; } return m;};Menu operator++(Menu & m, int) // m++{ Menu const old_m = m; switch (m) { case NewGame: m = Highscore; case Highscore: m = Exit; case Exit: m = NewGame; } return old_m;};Menu operator--(Menu & m, int) // m--{ Menu const old_m = m; switch (m) { case NewGame: m = Exit; case Highscore: m = NewGame; case Exit: m = Highscore; } return old_m;};
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement