Given this popular solution for "enum inheritance" (probably better called "extension"), would it be possible to raise a compiler error if I redefine an enumerator identifier of the base class in the derived class?
Example:
struct Enum
{
enum
{
One = 1,
Two,
_last
};
};
struct EnumDeriv : Enum
{
enum
{
Three = Enum::_last,
Four,
One //<--- this compiles but I'd like to get a compiler error instead
};
};
What happens here is that EnumDeriv::One
masks (is this the right term?) the definition of Enum::One
. So EnumDeriv::One
will now map to the "unexpected" integer value of 5
.
This could create some hard-to-debug errors if we derive from Enum
and inadvertently redefine some of its enumerator identifiers.
Any solutions of how to turn the "masking" into a compiler error or a suggestion for a similarly elegant "enum inheritance" solution that does not have this potential source of error would be welcome.