enum in a subclass ...

Hi friends,
i want to ask if somebody know a way to arrange next circumstance :
Inside a base class we have a enum :
class Base {
public:
enum Enum { obj1, obj2, obj3 };
Base();
};

class Deriv : public Base
{
public:
Deriv();
};

Originary i have all packet, so i have many places in my code in which i access my class like :
function(Deriv::obj1);
?
I tried also to make something like :
class Deriv : public Base
{
public:
typedef Base::Enum Enum;
Deriv();
};

But this not help very much.
Thanks for any help.
Daniel
But this not help very much.
What's the problem with Deriv::obj1 or respectively Base::obj1?
Hi danjiun ,
Can you please explain what problem are you facing .
While writing code use <code> </code> blocks .
Last edited on
Thanks for you reply.
I have defined a function as :
1
2
 
void function(Deriv::Enum o);

but, of course Deriv not contains directly enumeration Enum.
So, compiling, compilator throw a "undefined reference ..." say it not have
 
void function(Base::Enum o);

because, i make a use of this function with :
 
function(Deriv::obj1);

So, my question is next : it is possible to arrange Deriv in a way that i still can use Deriv, and enumeration elements like there are at Deriv ?
I wish to no need to write
 
function(Base::obj1);

for have it more clean.
greatings, Daniel
The code that you have posted looks fine. No need to use typedef or anything. The error "undefined reference" means it can't find the definition of the function.
Hi
but it not compile.
For a moment, i redefine for :
1
2
 
void function(Base::Enum o);

and like this it compile.
I dont know if it is a intrinsic problem of C++. Compiler is gcc x86, at 64 bits inside Linux.
Or may be i be am wrong. I already program 17 years in C++, and this is a first time i encounter a problem like this. Now i use already 1-2 years, C++11
Thanks for any help.
Daniel
This code works fine.

1
2
3
4
5
6
7
8
9
10
11
12
13
class Base {
public:
	enum Enum { obj1, obj2, obj3 };
};

class Deriv : public Base {};

void function(Deriv::Enum o) {}

int main()
{
	function(Deriv::obj1);
}

Note that Deriv::Enum is the same type as Base::Enum so it doesn't matter which one you write.
Last edited on
Thanks.
Before it not compile.
But, after i recompile , it works also.
Thanks, Daniel
I still don't see your problem. You should be able to access Enum via Deriv and/or Base without problems.

Provide an example where the problem actually occurs.
May be, previously not work because i use Qt, and it use a intermiddle file.
Precisely, function its a function as a signal :
1
2
signals:
    void tagOperation(TagExtHistorial::Operation op);

Qt produce additionally "moc"-files.
So , sometimes, if it appear strange errors, its good to recompile.
Daniel
Topic archived. No new replies allowed.