If we are using deep copy instead of shallow copy doesn’t that lead to redundancy as one object is the copy of the other and the changes made by one object should have impact over other, but we are doing opposite.
Copy constructor
@dishask99 In deep copy new dynamically memory is allocated and pointer do not point original memory allocation ,it points to new copied location ,it dont leads to redundancy as changes in original one donot make change to other one as both are different memory locations.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 disasterous consequences.If an object has pointers to dynamically allocated memory, and the dynamically allocated memory needs to be copied when the original object is copied, then a deep copy is required.
Hope you get it ,if you have any doubt than please ask
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.