Enums in C++0x
This is good news for C++: Herb Sutter reports that in July the ISO C++ committee voted better enum support into the language.
It’s all good, but the part that’s affected me in the past is the scoping of enum values. Previously:
1 <p>class MyClass<br>{<br> enum BorderColor { Red, Green, Blue };<br>};</p>
The values Red, Green, and Blue were scoped to MyClass, not to BorderColor. So you couldn’t say MyClass::BorderColor::Red, you had to say MyClass::Red. If your class has a lot of enums in it, they all get scoped to the class and this just gets messy.
Of course they can’t just change the language without risking compatibility so the new syntax will look like:
1 <p>class MyClass<br>{<br> enum class BorderColor { Red, Green, Blue };<br>};</p>
I can live with that.
Check out the full details here.
June 3rd, 2008 at 10:18 am
Enums in C++ Suck…
Like most strongly typed languages, C++ has a way to group a set of constants together as their own type called enums. Enums are extremely useful in a wide variety of circumstances. However, enums in C++ have a lot of problems, and, in fact, they’re r…