Is there a way in C++ to extend/"inherit" enums?
I.E:
enum Enum {A,B,C}; enum EnumEx : public Enum {D,E,F};
or at least define a conversion between them?
Answers. Yes, you can easily define a enumeration extending existing enum.
No, we cannot extend an enum in Java. Java enums can extend java. lang. Enum class implicitly, so enum types cannot extend another class.
This is not possible. Enums cannot inherit from other enums.
No, there is not. enum are really the poor thing in C++, and that's unfortunate of course. Even the class enum introduced in C++0x does not address this extensibility issue (though they do some things for type safety at least).
No, there is not.
enum
are really the poor thing in C++, and that's unfortunate of course.
Even the class enum
introduced in C++0x does not address this extensibility issue (though they do some things for type safety at least).
The only advantage of enum
is that they do not exist: they offer some type safety while not imposing any runtime overhead as they are substituted by the compiler directly.
If you want such a beast, you'll have to work yourself:
MyEnum
, that contains an int (basically)you may now extend your class (adding named constructors) at will...
That's a workaround though, I have never found a satistifying way of dealing with an enumeration...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With