The copy constructor is an element of the language.
A prototype is a design pattern used to create (polymorphic) objects based on some existing instance.
It would be difficult to use the former to implement the latter, since the copy constructor is intended to be used when knowing the exact instance of the object, while the prototype is used when there may be some possible implementation of an interface, and you just want to get a new object of exactly the same implementation without resorting to some strange casting and checking methods.
Suppose you have interface I and implementations A and B At some point, you are given an object I that implements I You may not want to modify it, instead you prefer to get a new instance, and then make some changes to it. How can this be achieved if you do not know the exact class I ? The prototype template is one of the solutions to this problem: I* i2 = i.clone(); .
source share