Re: New strongly type enum proposal featuring inherited enums
On 2011-08-16 21:28:17 +0000, Phil Bouchard said:
Hi,
Is it too late to change the strongly type enum?
Yes, C++11 has been unanimously approved. It will be an official
standard in a few weeks.
No, work is just starting on the next version of the C++ standard.
I have a proposal
that is much cleaner than what is on its way.
Right now we have:
enum class Val: unsigned long { E1, E2, E3, E4 };
Comments:
1) This design is bad because the ':' sign is reserved for inheritance.
Really? Where does the standard say that it's "reserved"? <g>
It's currently used to indicate inheritance, to separate two
expressions in a ternary operator, and to mark the size of a bitfield.
2) Inheriting from another enum would be quite useful. For example:
enum class Widget {button, combobox, listview};
enum class SuperWidget : Widget {iconview}
This way iconview would be equal to 3, not 0.
Sure. That's not precluded by using ':' to indicate that an enum is
based on an integral type.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]