Virtual constructors

Viewed 5798

I was wondering what is the meaning of a virtual constructor and how would it be used.

In addition I know that C++ does not allow for a virtual constructor, and I was wondering why.

3 Answers

Virtual constructor Fully Explained As the virtual constructor or any constructor is called automatically just after the creation of object or we can say it is the guaranteed first function that will run in the life-cycle of the object. Also Virtual function is needed when we are in the need of binding the base class pointer to derived class object and this is done through late binding which is achieved at runtime but the constructor is bond at compile time to confirm that there is need of creation of default constructor or not. Also, to late binding there is need of virtual pointer which is not created at compile time.

Related