How do I extend an enum?

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


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?




More information about the Digitalmars-d-learn mailing list