class A{
public:
int var;
virtual int getVar() { return var; }
};
class B: public A{
public:
int anothervar;
int getAnotherVar() { return anothervar; }
};
class C: public A{
public:
int finalvar;
int getFinalVar() { return finalvar;}
};
int main () {
vector<A*> myvec;
myvec.push_back (new B()); // implying all constructors are ok
myvec.push_back (new C());
cout << myvec[0]->geVar(); // this works fine
cout << myvec[0]->getAnotherVar(); // how can I do this ?
cout << myvec[1]->getFinalVar(); // how can I do this ?
return 0;
}
This is just a representation of another problem I'm trying to solve. So my question is, if it is possible to call derived classes methods, from a pointer vector of a base class since I cannot declare them as pure virtual at the base, because I don't want to use them in both derived.