Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Help in Vectors (http://www.go4expert.com/forums/help-in-vectors-t26228/)

Pritha 7Jul2011 17:19

Help in Vectors
I hava a base class and a derived class as below:

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.

xpi0t0s 8Jul2011 11:34

Re: Help in Vectors
Yes of course, that's the whole point of polymorphism.

All times are GMT +5.5. The time now is 20:32.