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
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
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
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.