Copy Constructor and Assignment Operator

Hey guys.

I've been working on some project and I got to wondering when you know you need to use a copy constructor and an assignment operator. Is there a rule of thumb? I know there is the Rule of Three, but is there something that tells you when you need those three?
When any class/struct members are pointers.
If you haven't seen this article yet, it might be worth a read?

Copy constructors, assignment operators, and exception safe assignment
http://www.cplusplus.com/forum/articles/18749/

Andy
closed account (zb0S216C)
Tresky wrote:
"is there something that tells you when you need those three?"

Nope. Whether or not you need to enforce the Rule of Three depends on your class' design. Typically, when your class contains a pointer or reference of some sort, then it's likely that you will need to incorporate the Rule of Three. However, the Rule of Three doesn't apply to just pointers or references, but possibly other class types such as "std::fstream".

Wazzak
> when you know you need to use a copy constructor and an assignment operator
when the defaults provided by the compiler are not good.
Topic archived. No new replies allowed.