Copy constructor

Jul 29, 2012 at 9:53am
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 Jul 29, 2012 at 9:53am
Jul 29, 2012 at 9:59am
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)
Jul 29, 2012 at 10:00am
Thank you a lot!
Topic archived. No new replies allowed.