I want to get a backup of a object. So, I was going to write a copy constructor for the class to copy this object to a backup one. But I found several raw pointer members in that class. Thus, implementing a copy constructor would be as hard as implementing a smart pointer. Besides, the class is too old and complex to be rewritten. Is there another way to achieve the backup task of the object besides implementing copy constructor?
Can you make a new class, inherit the old class and add data memebers to store the state of the objects the pointers are referencing?
Would it be easier to just save a raw copy of the memory heap? This would be library dependent but I know Win32 has a couple functions to accomplish this. Which libs are you using?
SomeClass & SomeClass(const SomeClass & oldObject){ // this also work with assigment operator
member = oldObject.member; // assigment operator
// or
member(oldObject.member) // copy constructor
// or pointers
member = new SomeMember();
member* = (oldObject.member)*;
}
If the member types are primitive types or classes it should work just fine because they will generate a copy-constructor ( see rule of three) if the members are pointers you have to copy the content of that pointer. using either operator * or operator ->.