How to require inherited class to include an enum?

G

Guest

I was hoping to code a base class that would somehow require inheriting
classes to define an Enum.
Each inheriting child class needs to define it's own enum with it's own
enumerated values, which are unique for that child class. I can't find a way
for a base class to required this. Any ideas?

TIA
 
G

GhostInAK

Hello RJ,

HA! That would seriously violate the rules of inheritance. And even if
you could somehow violate these rules.. you now have a violation with the
..NET type checking.

Your base class can not require an inherited class to implement it's own
enum. Just not possible. Either define an enum on the base class that includes
all possible values... or redesign the mechanism that uses the enum so it
no longer uses an enum... or move the entire enum-requiring mechanism outside
the pervue of the base class.

-Boo
 
P

Phill W.

RJ said:
I was hoping to code a base class that would somehow require inheriting
classes to define an Enum.

No can do. A base class has remarkably /little/ control over what a
subclass /has/ to do.
Each inheriting child class needs to define it's own enum with it's own
enumerated values, which are unique for that child class.

Why? What would you expect the subclasses to /do/ with this Enum about
which the base class knows nothing?
I can't find a way for a base class to required this.

Probably because there isn't one.

Take a step back and tell us what you're trying to achieve and we'll see
if we can suggest anything. :)

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top