Re: New strongly type enum proposal featuring inherited enums
Phil Bouchard wrote:
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.
I see no problem so far.
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.
I had the same idea some time ago. However, poeple told me that it is
not that easy.
First of all inheriting from a type implies that slicing is possible.
But SuperWidget can't ever be safely converted to Widget, becuse
Widget can't take the value iconview. In fact it is the other way
around. Widget is Safely a SuperWidget. The covariance/contravariance
is swapped.
3) Redefining the underlying type could be easily done with:
enum class Val { unsigned long E1, E2, E3, E4 };
This implies that the type is specific to each enum constant. It isn't. IMO
enum class Val: unsigned long
is fine. Val is an unsigned long, but it cannot be implicitly
converted because it is a private base.
Marcel
--
[ 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 ]