www.digitalmars.com         C & C++   DMDScript  

D - extending enums

reply "Pavel Minayev" <evilone omen.ru> writes:
I thought it would be fine if enums were extensible:

    enum Color { red, green, blue };
    // somewhere later
    enum Color { yellow, cyan, magenta };    // Color.yellow = Color.blue +
1

Not useful as is, but could be very handy if applied
to class hierarchy. So the base class declares the
enum and introduces basic options common for all, and
then child classes add options specific to their
functionality.

Or maybe use the class syntax for enums, with inheritance
and such? A stupid idea, probably, but... =)
Nov 24 2001
parent "Walter" <walter digitalmars.com> writes:
This idea has come up before, and it's a good one. -Walter

"Pavel Minayev" <evilone omen.ru> wrote in message
news:9to6n8$12d6$1 digitaldaemon.com...
 I thought it would be fine if enums were extensible:

     enum Color { red, green, blue };
     // somewhere later
     enum Color { yellow, cyan, magenta };    // Color.yellow = Color.blue
+
 1

 Not useful as is, but could be very handy if applied
 to class hierarchy. So the base class declares the
 enum and introduces basic options common for all, and
 then child classes add options specific to their
 functionality.

 Or maybe use the class syntax for enums, with inheritance
 and such? A stupid idea, probably, but... =)
Nov 24 2001