I wanted to use the enum to make sure that anyone using the class could not assign an integer value to m_evil (in this example) and exceed the limits of the enumeration. If the constructor accepts formal parameter of type evil, then the user must specify something in the enumeration -- not just an integer -- so in this case it isn't really acting as a symbolic constant.
1 2 3 4 5
|
this_class evilness = this_class(2) // compiler error
this_class evilness = this_class(this_class::mostly) // same value, but needs scope resolution
const this_class::evil mostly = mostly;
this_class evilness = this_class(mostly) /* now works, is OOP, doesn't require scope resolution
but does require a const for each enum value to be declared in addition to defining the enumeration*/
|
The problem is, it breaks OOP because OOP says if I change the implementation (by changing enum evil to an integer on a whim) that I will have broken the interface because this_class::very no longer exists. In fact, when anyone using the class types in this_class::very as a formal parameter, they automatically KNOW it's an enumeration (if they know C++) because any other basic type would not require scope resolution.
That is my beef with type enum: each value requires scope resolution in the program in order to use it. The only way I found around that is what I originally posted -- using a symbolic constant that stands in for an enumeration value of the same name. That just doesn't seem right to me.
Please accept that I am very new at C++, I'm only on chapter 10 of Prata, but I found this dilemma by accident and it puzzled me. I guess I don't really have a specific question about enumerations -- more specifically, I was hoping someone would look at how I was using it, and say, "Ah... there is a better way to do what you intend, and here it is:" followed by their wisdom.