Rule of three (C++ programming)

The rules prescribe how the default members of a class should be used to achieve these goals systematically.

The rule of three (also known as the law of the big three or the big three) is a rule of thumb in C++ (prior to C++11) that claims that if a class defines any of the following then it should probably explicitly define all three:[1] These three functions are special member functions.

If one of these functions is used without first being declared by the programmer it will be implicitly implemented by the compiler with the following default semantics: The rule of three claims that if one of these had to be defined by the programmer, it means that the compiler-generated version does not fit the needs of the class in one case and it will probably not fit in the other cases either.

[2] An amendment to this rule is that if the class is designed in such a way that resource acquisition is initialization (RAII) is used for all its (nontrivial) members, the destructor may be left undefined (also known as The Law of The Big Two[3]).

If the default behavior ("shallow copy") is actually the intended one, then an explicit definition, although redundant, will be "self-documenting code" indicating that it was an intention rather than an oversight.