Why Constructor can’t be virtual ?

Constructor is a special type of default member function of the class, Which have the same name as class and doesn’t have any return type. It Instantiate the class means it puts the object data in to memory and create a virtual table.  So there has to be an existing object with a pointer which points to the vtable(virtual table) and all this done at compiler. So by  writing virtual keyword before constructor means by making constaructor as virtual means that  there is no object  and then no vtable will be in existence.  That’s why,  It is not possible to have any virtual constructor.
 

85 total views, 5 views today

Posted in

Leave a Reply