Q:

C++ Call child function on vector of parent objects

Imagine I have a class A. B & C both inherit from A. B' Inherits from B.
B" has a member variable which is a vector of A pointers. 
I create a new B" called bP and store a new C inside, called c.
Now I want to call c.f(), a function that only exists for type C.
I call bP[0]->f(). 
The error I get is "f(): is not a member of 'A'". 
Is it possible for me to call a child function from a vector of parent objects? 

A:

I believe your code structure is something like this :

class A
{
};

class B: public A
{
};

class C: public A
{
};

class B': public B
{
    public:
           vector<A*> vec;
           B(class C* c)
           {
               vec.push_back(c);
           }
}; 

int main()
{
    C *c = new C();
    B'* b = B'(c);
    C* c = static_cast<C*>(((b->vec).front())->f());  //Downcasting
    return;
}

