Why C ++ constructors can not be virtual

1. Storage space angle: corresponding to a virtual function vtable, vtable object stored in the memory

If the constructor is virtual, you need to call through the vtable, if the object has not been instantiated, that memory is never, can not find the vtable

2. Angle: virtual function is mainly used in case of incomplete information, allows overloaded functions to obtain the corresponding call.

The constructor to initialize itself instance, that the use of virtual functions is no practical significance

3. From a practical point of view meaning, can not determine the true type of the object in the constructor is called Shihai (because subclasses will bring up the constructor of the parent class); and the role of the constructor is to provide initialization is performed only once in the lifetime of the object, dynamic behavior is not the object, there is not much need to be a virtual function

Guess you like

Origin www.cnblogs.com/sylar5/p/11525113.html