tags:

views:

246

answers:

1

I believe the new C++ standard allows for an extra "scope" for enumerated types:

enum E { e1, e2 };

E var = E::e1;

Since I know lots of source files containing the old C-style enum typedef, I wondered if the new standard would allow using the typedef for these otherwise anonymous enumerated types:

typedef enum { d1, d2 } D;
D var = D::d1; // error?
+5  A: 

The new standard will add a new type of strong enum, but the syntax will be slightly different, and old style enums will be compatible (valid code in C++03 will be valid C++0x code) so you will not need to do anything to keep legacy code valid (not the typedef, not anything else).

enum class E { e1, e2 }; // new syntax, use E::e1
enum E2 { e1, e2 }; // old syntax, use e1 or E2::e1 (extension)

There is a C++ FAQ here that deals with this particular issue.

David Rodríguez - dribeas
I think the OP knows the typedef is not necessary, he's just concerned about legacy C code that uses it.
Manuel
Legacy code will use the old style enums, and those enums (the one in the OP) will bring the names into the enclosing scope. I am editing the answer so that it is clearer.
David Rodríguez - dribeas