Inherit enum members

Alex AJ at gmail.com
Sun Apr 21 22:58:01 UTC 2019


On Sunday, 21 April 2019 at 20:58:19 UTC, Andrey wrote:
> Hello,
> I have got 2 enums. How to inherit one enum from another?
>> enum Key : string
>> {
>>     K1 = "qwerty",
>>     K2 = "asdfgh"
>> }
>> 
>> enum ExtendedKey : Key
>> {
>>     E1 = "q1",
>>     E2 = "w2",
>>     E3 = "e3"
>> }
>
> Result:
>> onlineapp.d(27): Error: cannot implicitly convert expression 
>> "q1" of type string to Key
>> onlineapp.d(28): Error: cannot implicitly convert expression 
>> "w2" of type string to Key
>> onlineapp.d(29): Error: cannot implicitly convert expression 
>> "e3" of type string to Key
>
> How to understand this?

I don't know why you want to do this, just use string directly.


enum ExtendedKey : typeof(EnumMembers!Key[0])
{
     q = EnumMembers!Key[0]
}


would work..

Alternatively look at this thread:

https://forum.dlang.org/thread/irvtrixunermburvviib@forum.dlang.org?page=2

Where you can use the code and classes to subtype and emulate 
enums.







More information about the Digitalmars-d-learn mailing list