- Why does C++ not allow a virtual constructor?
There are several reasons, but the simplest is that the memory must be allocated in the amount sizeof(T), where T is the actual object type, and the sizeof() operator is constexpr (a compile-time constant).
- What is the Factory pattern?
The Factory pattern is a creational pattern that solves the problem of creating objects without having to explicitly specify the type of the object.
- How can we use the Factory pattern to achieve the effect of a virtual constructor?
While in C++ the actual type has to be specified at construction point, the Factory pattern allows us to separate the point of construction from the place where the program has to decide what object to construct and to identify the type using some alternative identifier, a number, a value, or another type.
- How can we achieve the effect of a virtual copy...