J
john smith
Hi, I'm trying to do something like this:
class A {
public:
virtual void f() {
// do something
}
};
class B : public A {
// some methods here
};
class C {
public:
C(A* a)
{
a_ = new WHAT?!?! // could be either A or B!!
}
A* a_;
};
In general, there could be more classes derived from A or B.... Assuming
there are copy constructors and assignment operator defined for A and B.
How can I initalize a_? do I have to resort to RTTI if-else ladders!?
There is got to be a better way!
thanks
Smith
class A {
public:
virtual void f() {
// do something
}
};
class B : public A {
// some methods here
};
class C {
public:
C(A* a)
{
a_ = new WHAT?!?! // could be either A or B!!
}
A* a_;
};
In general, there could be more classes derived from A or B.... Assuming
there are copy constructors and assignment operator defined for A and B.
How can I initalize a_? do I have to resort to RTTI if-else ladders!?
There is got to be a better way!
thanks
Smith