Is it possible to have virtual constructors? Explain the answer.
yes,we can have virtual constructors.
No. We can't have virtual constructors. It is a compile time error.
It depends on the situation, some times it is possible.
No. virtual table will be created after constructor is called (after object is created), not at the time of constructor call. So if you don't have virtual table you can't have before constructor being called, you can't have virtual mechanism working for you.
Constructor has its own cycle, first it executes base and then derived.
So no point of having virtual here.
Reason from Bjarne Stroustrup (who created c++): A virtual call is a mechanism to get work done given partial information. In particular, "virtual" allows us to call a function knowing only any interfaces and not the exact type of the object. To create an object you need complete information. In particular, you need to know the exact type of what you want to create. Consequently, a "call to a constructor" cannot be virtual.
VTable is created before constructor.Vptr is initialised at the time of costructor
Back To Top