Difference between deep copy & shallow copy
A shallow copy (bitwise copy) of an object copies all of the member field values. This works well if the fields are values, but may not be what you want for fields that point to dynamically allocated memory. The pointer will be copied. But the memory it points to will not be copied
A deep copy copies all fields, and makes copies of dynamically allocated memory pointed to by the fields. To make a deep copy, you must write a copy constructor and overload the assignment operator; otherwise the copy will point to the original, with disastrous consequences.
Jan 21, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment