I'm seeking advice on how do I implement a copy constructor of an unknown derived type?
Consider the following:
I'm designing an app that will allow other developers to write their own plugins that conform to a virtual interface, Vehicle.
Developers may wish to create Car, Tank, or Motorbike plugins.
Class Tank : public Vehicle ...
Class Car : public Vehicle ...
I want the app to make copies of the derived classes; but these classes are unknown to my app at compile time because they have been dynamically loaded via a plugin system by the end-user at runtime.
Vehicle * newCopyOfVehicle = new Vehicle(myExistingCarClass); // Only copies the base class, not the derived class.
It seems to me that I should ask the class to make a copy of itself and report back to the app with an Vehicle interface?
Is this a good idea?