www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Simulating enum inheritance?

reply Dwayne Robinson <Dwayne_member pathlink.com> writes:
How can you simulate enumeration inheritance so that later enums can
automatically adopt all the constants of an earlier one?

Application: I have basic messages that all GUI objects support and more
specific messages to each type. Obviously a Button should messages specific to
Lists (and vice versa) but they both understand things like redraw, move,
destroy...

I could fully qualify the enum reference every time I wanted to use something
from the main class, but ... I'm in no hurry to develop carpal tunnel :) I could
use mixins except they don't seem to work for enums (complains about items
separated by commas rather than semicolons).

Ideas? (I'm using enums for good reason)
Thank you.
Nov 02 2005
parent "Lionello Lunesu" <lio remove.lunesu.com> writes:
 Ideas? (I'm using enums for good reason)

Hmmm.. A static foreach comes to mind :-) No, don't look for it, it's not there. For the record, I remember an interesting point raised by Walter a few years ago: 'inherited' enums would behave differently from inherted classes in that an inherited class can be cast safely to the base, but an inherited enum (one with more values) cannot. In fact, the base enum can be cast to the inherited one.. I've always thought this was an interesting point. L.
Nov 03 2005