I l @ ve RuBoard |
C++ is stricter about using enumerations than C is. In particular, about the only useful things you can do with an enum variable are assign an enum constant to it and compare it to other values. You can't assign int s to an enum without an explicit type cast, and you can't increment an enum variable.
enum sample {sage, thyme, salt, pepper}; enum sample season; season = sage; /* ok in C, C++ */ season = 2; /* warning in C, error in C++ */ season = (enum sample) 3; /* ok in C, C++ */ season++; /* ok in C, error in C++ */
Also, C++ lets you drop the keyword enum when declaring a variable:
enum sample {sage, thyme, salt, pepper}; sample season; /* invalid C, valid C++ */
As was the case with structures and unions, this can lead to conflicts if a variable and an enum type have the same name .
I l @ ve RuBoard |