How do I extend an enum?

Lass Safin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Mar 19 10:41:29 PDT 2016


On Saturday, 19 March 2016 at 17:40:27 UTC, Lass Safin wrote:
> Why:
>
> enum Base {
>     A,
>     B,
> }
>
> enum Derived : Base {
>     C, // Gives error, says it can't implicitly convert 
> expression to Base.
>     D = 1, // Same error
>     E = cast(Base)294, // Finally works. Can only be 
> cast(Derived) instead.
> }
>
> void func(Derived d) {}
>
> func(Derived.E); // works.
> func(Derived.A); // Gives error, says it can't call function 
> with Base.A.
> func(cast(Derived)Derived.A); // Works.
>
> So, what's the proper way of extending an enum?

Meant "Can also be cast(Derived) instead."


More information about the Digitalmars-d-learn mailing list