Try this:
enum Direction { Left, Right }; void stick(int a, inb &b, Direction d); { switch (d) { case Left: break; case Right: break; } // ... }
Note that enum in C ++ to C ++ 11 versions gives a rather weak typing. For example, such code is compiled:
enum Direction { Left, Right }; enum Direction2 { North = 5, South = 7 }; void f(Direction d) { switch (d) { case North: break; case South: break; } // ... }
For the compiler, all enum 's are just numeric constants.
But starting with C ++ 11, it is better to use a strongly typed enum :
enum class Direction { //^^^^^ Left, Right }; enum WrongDirection { Left = 1, Right = 0 }; void f(Direction d) { switch (d) { case Direction::Left: // а не WrongDirection::Left break; case Direction::Right: break; } // ... }
Here the compiler will not let you accidentally use the wrong type.
enum? - VladD