The typical pattern when you want to copy a polymorphic class is adding a virtual clone method and implement it in each derived class like this:
Base* Derive
You could use CRTP
to add an additional layer between your derived class and base that implements your cloning method.
struct Base {
virtual ~Base() = default;
virtual Base* clone() = 0;
};
template
struct Base_with_clone : Base {
Base* clone() {
return new T(*this);
}
};
struct Derived : Base_with_clone {};