Copy constructor

Why do we bother and make a copy constructor in a class?
I did not understand the documentation attached to this topic.
Thank you
Last edited on
When an object is copied some odd, unwanted behaviour can occur, e.g if your copied object goes out of scope and the destructor is called it may destroy some resource that the original object needs (file, memory, image whatever.)

When you create a copy constructor you can change the way it behaves when the object is copied so you can stop unwanted behaviour (such as destroying stuff you still need)
Thank you a lot!
Topic archived. No new replies allowed.