I am trying to access derived class' private members via an object of the base class. Here is what I'm trying to do :
class A {
private:
int a, b;
public:
A(_a, _b) : a(_a), b(_b) {}
int getA() { return a; }
int getB() { return b; }
};
class B : public A {
private:
int c;
public:
B(_a, _b, _c) : A(_a, _b), c(_c) {}
int getC() { return c; }
};
vector<A*> objects;
A* retVal = new B(1,2,3);
objects.push_back(retVal);
Now how is it possible to access this?
objects[0] -> getC();
I am a little confused.
Thanks in advance.