LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-27-2006, 04:35 PM   #1
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
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.
 
Old 01-27-2006, 05:25 PM   #2
Hivemind
Member
 
Registered: Sep 2004
Posts: 273

Rep: Reputation: 30
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.
 
Old 01-27-2006, 10:14 PM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Original Poster
Rep: Reputation: 148Reputation: 148
Essentially I require a forward declaration, but I thought it wasn't possible, just wanted confirmation.

Thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HOTSWAP: where to find #ENUM signal? iflorea Programming 0 11-20-2005 06:58 AM
C Enum exvor Programming 3 09-27-2005 02:51 PM
C, enum confusion cigarstub Programming 2 09-27-2005 09:59 AM
python inheritance towlie Programming 3 09-23-2004 12:13 AM
inheritance kalleanka Programming 4 02-29-2004 07:19 PM


All times are GMT -5. The time now is 09:19 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration