ccs wrote:
In Meyers' book he gave an example of "virtual copy constructor",
which is quite different to an "ordinary" copy constructor by:
1. it returns a pointer to an object instead of a reference.
2. it have empty argument list.
3. it has "virtual" keyword in front of it.
My questions are:
1. How could "virtual" be used in front of a constructor even though
it's a "copy constructor"?
The name "virtual copy constructor" doesn't mean it's a constructor
(which is why I don't like that name much).
2. Can an "ordinary" copy constructor be "virtual?
No. Constructors can't be virtual. A virtual function behaves
polymorphically, i.e. if you call it through a pointer to a base class
that points to an instance of a class derived from it, the
implementation of that derived class is called. This wouldn't make any
sense for constructors, since they are used to create the object. There
is no object before the constructor is called, and it basically gets
its type because the constructor of that type is called. So how would
the compiler decide which constructor to call in the case of a virtual
one?