enum provides some type security for the caller ... for example, they cannot pass int as a parameter when Foo::Stooge is expected, or initialize Foo :: Stooge with (uncast) int or enum another type.
A BobTFish comment correctly points out that there is still a lot of nasty code that compiles - more than I remember, as I am not trying to write bad code to keep track of the edges of the compiler check! C ++ 11 improves this for enum class es.
In addition, if you add the function a std::ostream& operator<<(std::ostream&, Stooge) , they can pass a value - the implementation can guarantee a symbolic name (that is, they actually saw "larry", "moe" or "curly" in the stream).
source share