helo i read many books but i cant find the proper answer that why
constructor cannot be virtual
can u explain me in simple term that why constructor cannot be virtual
Regards,
Amit
Because some properties of a virtual function does not apply to constructor such as "run time binding", besides why would you want a virtual constructor ???
Virtual works by the object pointing to a v-table, and the caller dereferencing the call via the v-table. Immediately prior to construction time you don't have an object which points to a vtable to make the call.
Solutions to this include using factory objects, which is exactly what COM does with IClassFactory so the call to CreateInstance is virtual. Similarly IBM's SOMClass::somNew.