Originally Posted by
std10093
So this is why enums are useful?They have no more advantages?
Laserlight actually gave a complete response, but clearly you failed to draw the critical conclusion about type safety.
With enums, you will get error messages if you do
Code:
enum TreeType
{
maple, douglasFir, Alder
};
enum DogType
{
labrador, poodle
};
int main()
{
TreeType some_tree;
some_tree = poodle; // Oops!
}
But the compiler will not complain at all if you do
Code:
/* Tree types */
const int maple = 0;
const int dougladFir = 1;
const int Alder = 2;
/* Dog types */
const int labrador = 0;
const int poodle = 1;
int main()
{
TreeType some_tree;
some_tree = poodle; // Oops!
}
And, since it is not unrealistic to believe that code concerned with dogs might interact with code concerned with trees..... dogs behaving as they do and all ......