Is there any way to have it call the derived class's function? I need to be able to store two different kinds of Derived classes by pointer, unless there's a better way.
class Base{
public:
void foo() {
cout << "Base";
}
}
class Derived1 : public Base {
public:
void foo() {
cout << "Derived1";
}
}
class Derived2 : public Base {
public:
void foo() {
cout << "Derived2";
}
}
Base *obj;
Derived1 o1;
obj = &o2;
obj->foo(); // Can I have it call Derived1's foo()?
I need to store a bunch of objects of both Derived classes in the same "place"
This post has been edited by demosthenes2k8: 04 February 2011 - 01:22 PM

New Topic/Question
Reply




MultiQuote



|