cloning

C++: Polymorphic Cloning and the CRTP (Curiously Recurring Template Pattern)--Katy Coe

katy.pngOn CRTP with multi-level inheritance, cloning, and the constructor forwarding problem.

C++: Polymorphic cloning and the CRTP (Curiously Recurring Template Pattern)

by Katy Coe

From the article:

A common problem in C++ occurs when you have an object of an unknown derived type and want to make a copy of it. ...

The solution is to use the commonly-used polymorphic cloning pattern. In this pattern, we define a virtual function -- which we’ll call clone() in this article -- which when called via an object pointer returns a new object of the correct derived type.

Continue reading...