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.

1,891 total views, 10 views today

Posted in

Leave a Reply