LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   enum inheritance in C++? (https://www.linuxquestions.org/questions/programming-9/enum-inheritance-in-c-408714/)

graemef 01-27-2006 04:35 PM

enum inheritance in C++?
 
Okay I don't think this is supported but I just wanted to check.

Essentially I have a base class where I wanted to declare an enum and then in the derived classes define it. I can't think of or discover a way of doing this.

The reason for this is that I wanted put the abstract methods that use the enum in the base class, to ensure that the derived class declare the required methods.

My work around is to make the arguments int in the method but from the implementation I pass the variable as an enum. This works but it misses the compile check on the valid range (and missing cases in a switch.) unless I remember to typecase the parameter begin passed in. This is okay since at the moment I remember why I'm doing this in the future I may not remember...

Any ideas, suggestions are welcome.

cheers,

graeme.

Hivemind 01-27-2006 05:25 PM

What do you mean by define the enum in the derived class? There's no such thing as forward declarations for enums, meaning you can't do:

Code:

enum foo; /* trying to forward declare enum = error */
Simply put the definition of the enum where it's first needed, in your case in the base class.

graemef 01-27-2006 10:14 PM

Essentially I require a forward declaration, but I thought it wasn't possible, just wanted confirmation.

Thanks.


All times are GMT -5. The time now is 11:53 PM.