When should we write our own copy constructor?

Don’t write a copy constructor if shallow copies are ok: In C++, If an object has no pointers or any run time allocation of resource like file handle, a network connection..etc, a shallow copy is probably sufficient. Therefore the default copy constructor, default assignment operator, and default destructor are ok and you don’t need to write your own.

Source: http://www.fredosaurus.com/notes-cpp/oop-condestructors/copyconstructors.html

My Personal Notes arrow_drop_up

Practice Tags :
Article Tags :
Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.

Recommended Posts:

2 Average Difficulty : 2/5.0
Based on 27 vote(s)

User Actions