Click to See Complete Forum and Search --> : Make copy to new instance


lloydy
October 25th, 2004, 08:07 PM
Hi,

I have a number of default instances of a class that I build from a Database. What I would like to do is copy these default instances to a new instance when required.

MyClass* DefaultInstance = new MyClass();
DefaultInstance->Load(ParamterA);


//then later
MyClass* NewInstance = DefaultInstance->MakeCopy()

The thing is that MyClass may be derived, and I may not know what it is. I don't want to have to make a MakeCopy function for all my derived classes and call by reflection.

Is there a way to copy (as in the old C++ of *NewInstance = *DefaultInstance)

Thanks