In one of the C++ tutorials in internet, i found out the below description on why a constructor cannot be virtual
We cannot declare a virtual constructor. We should specify the exact type of the object at compile time, so that the compiler can allocate memory for that specific type.
Is this description correct ?
I am getting confused particularly with the phrase: so that the compiler can allocate
memory for that specific type
.
virtual
because it simply wouldn't make sense. – DichoThing t;
ornew Whatever
). The compiler generates code based on this to allocate the right amount of memory, and call the correct constructor. – Heterogenesis