Given a base class that is inherited by plethora of derived classes, and a program structure that requires you manage these via base class pointers to each entity. Is there
template
Base* CopyDerived(const T& other) {
T* derivedptr = new T(other);
Base* baseptr = dynamic_cast (derivedptr);
if(baseptr != NULL)
return baseptr;
delete derivedptr;
// If this is reached, it is because T is not derived from Base
// The exception is just an example, handle in whatever way works best
throw "Invalid types in call to Copy";
}
This only requires a publicly accessible copy constructor in each derived class you wish to copy.