2

Is there any possibility to create an enum A which inherits properties of enum B and additionally provides possibility to extend elements?

Example:

Enum A
- one
- two
- three

Enum B:A
- four
j.a.estevan
  • 3,057
  • 18
  • 32
Nico
  • 1,175
  • 15
  • 33

2 Answers2

1

No, it is not possible. Base Enums do not support inheritance.

Skaue
  • 763
  • 4
  • 13
1

You can't, but if you manually create two base enums, the second with same labels and values of the first one, you can virtually "down cast" them on runtime like if they were inherited, this way (real code):

NoYes          e1; // 0 No, 1 Yes
NoYesError     e2; // 0 No, 1 Yes, 2 Error

e1 = NoYes::No;
e2 = e1+0; // Add zero to avoid compile error

info(strFmt("%1 %2", e1, e2));

e2 = NoYesError::Error;
e1 = e2+0; // Don't do that

info(strFmt("%1 %2", e1, e2));    

Hope this helps.

j.a.estevan
  • 3,057
  • 18
  • 32