The standard way of declaring an enum in C++ seems to be:
enum <identifier> { <list_of_elements> };
However, I have already seen some declarations like:
typedef enum { <list_of_elements> } <identifier>;
What is the difference between them, if it exists? Which one is correct?
C compatability.
In C,
union,structandenumtypes have to be used with the appropriate keyword before them:In C++, this is not necessary:
So in C, lazy programmers often use
typedefto avoid repeating themselves: