Enum inheritance

Matthias Walter walter at mail.math.uni-magdeburg.de
Wed Aug 15 11:28:03 PDT 2007


Witold Baryluk Wrote:

> Dnia Wed, 15 Aug 2007 14:13:09 -0400
> Matthias Walter <walter at mail.math.uni-magdeburg.de> napisa³/a:
> 
> > 
> > Can I do the following conversion with your code?
> > 
> > E2 bla = E2.E;
> > E3 foo = bla;
> > 
> no.
> you can do:
> E1 bla = E1.A;
> E3 foo = bla;
> 
> Enums in D are really integers, and it will not be so simple to do
> what you want. I don't know if opCast can be done with enums.
> 
> Mayby such trick:
> 
> enum E1 {
>     A, B, C
> }
> 
> enum E2 {
>     E = E1.max+1, F, G
> }
> 
> 
> then it will work.

But the compiler will complain that E1 and E2 are different types, so semantically, your updated version will work then, but you would still need a cast!

Thanks for your working version, but you see that it's not very easy to create (you need mixins) and use (need casts) the enums this way. I believe that some kind of enum inheritance is worth to be included in the language. Any other opinions or arguments, why this is not a good idea at all?

best regards
Matthias



More information about the Digitalmars-d mailing list