Why do we not have a virtual constructor in C++?

Hear it from the horse’s mouth. 🙂

From Bjarne Stroustrup’s C++ Style and Technique FAQ Why don’t we have virtual constructors?

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.

The FAQ entry goes on to give the code for a way to achieve this end without a virtual constructor.

Leave a Comment