Let's say I have this base class for a data container:
class BaseClass{
public:
int a;
int getA();
void setA(int newA);
}
And I have a derived class:
class DerivedClass : BaseClass{
public:
int b;
int getB();
void setB(int newB);
}
Now I create two instances of the derived class:
DerivedClass* first = new DerivedClass();
DerivedClass* second = new DerivedClass();
Ok, here is my question: How can I let second point to a deep copy of firsts object (without producing a memory leak)?
Also, I have to consider that the class / function which handles both pointers and wants to copy them isn't aware of the exact inheritated class. So those pointers could also point to another inheritance of BaseClass, and the copy function has to work still and copy all! members.