Help in Vectors

Pritha's Avatar, Join Date: Jul 2011
Newbie Member
I hava a base class and a derived class as below:
Code:
class base
{
//member fns
}
class derived::public base
{
//member fns
}
Now i have created a vector pointer for base class
std::vector<base*> pBase;
And an instance for derived class as well
derived* pDerived = new derived();

My query is :
is it possible to add the derived class object pointer in to the base class vector
i.e. pBase.push_back(pDerived);
Kindly explain me on this.

Last edited by shabbir; 7Jul2011 at 21:48.. Reason: Code blocks
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Yes of course, that's the whole point of polymorphism.