A constructor cannot be virtual because at the time when the constructor is invoked the virtual table would not be available in the memory. Hence we cannot have a virtual constructor.
I think the only way to create a "virtual constructor" is to make a virtual method that returns the object inquestion, where derived classes return a copy of their type instead of the base classes return implementation.
By casting a derived type to a base type and invoking the virtual constructor method, you're constructing an object virtually, therefore it's safe to say it is a "virtual constructor".
constructor can't be defined as virtual bcuz if a class contains virtual function then the associate vtable must be initiated by the constructor of that class.if we define constructor as virtual then it creates a problem that who initiates that vtable.
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.