C++'s Rule of Three

11    07 Jul 2015 09:32 by u/hopo

4 comments

1

This was just something I came across while relearning C++. C++11 has added move semantics so these guidelines have probably changed since then, but nevertheless, I found the read quite enlightening.

1

If I recall correctly it's now the rule of five ;D

1

When I learned c++, I would use constructors and destructors, but never really cared about a copy constructor or an assignment operator. Meh, it worked for me, but I appreciate the principle today.

1

More important since C++11, I think, is the Rule of Zero: "Classes that have custom destructors, copy/move constructors or copy/move assignment operators should deal exclusively with ownership. Other classes should not have custom destructors, copy/move constructors or copy/move assignment operators."