Possible Duplicates:
What is the copy-and-swap idiom?
Copy constructor and = operator overload in C++: is a common function possible?
Is there a way that I can make the body of the copy constructor and assignment operator contain the same code without actually having duplicate code (except for the function headers)?
One common way is the copy-and-swap idiom. You would have to implement a swap operation, but if done correctly, you have the additional benefit of having exception safe assignment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With