liveBook · Manning

Big five

The rule of five is a C++ guideline that classes managing resources should consider defining a destructor, copy constructor, copy assignment operator, move constructor, and move assignment operator.

How 2 Manning books explain it

100 C++ Mistakes and How to Avoid Them

The rule of five is a C++ class-design pattern in which a class considers defining a destructor, copy constructor, copy assignment operator, move constructor, and move assignment operator together.

How it is used
Coordinates copying, assignment, destruction, and ownership transfer in classes that manage resources.
How deep it goes
Defines the five operations and demonstrates deep copying, cleanup, and defaulted moves with smart pointers.
Examples
Contrasts costly copying with std::move and shows a Page using unique_ptr and defaulted move operations.
What you can do after
Apply the rule by adding move construction and assignment alongside copy operations and a destructor for resource transfer.

Read how 100 C++ Mistakes and How to Avoid Them explains big five →

Learn C++ by Example

The rule of five is a C++ design guideline that a class managing resources and declaring one relevant special member function should explicitly consider all five copy and move special member functions.

How it is used
Guides resource-managing classes when copy and move behavior must remain consistent.
How deep it goes
Explains the five operations, compiler suppression of moves, and compile-time inspection, but does not implement resource ownership.
Examples
Uses vector push_back and a polymorphic Blob class with static type-trait assertions.
What you can do after
Evaluate copy and move support with std::is_* type traits and recognize when implicit moves are unavailable.

Read how Learn C++ by Example explains big five →

What to know first

Related concepts

Questions about big five

What is big five?

The rule of five is a C++ guideline that classes managing resources should consider defining a destructor, copy constructor, copy assignment operator, move constructor, and move assignment operator.

Which Manning books explain big five?

100 C++ Mistakes and How to Avoid Them and Learn C++ by Example.

What should I know before learning big five?

Manning books that teach big five usually introduce copy assignment operator, copy constructor and initializer first.

What is the difference between big five and big three?

The rule of five is a C++ guideline that classes managing resources should consider defining a destructor, copy constructor, copy assignment operator, move constructor, and move assignment operator. The rule of three is a C++ resource-management guideline that a class defining a destructor, copy constructor, or copy assignment operator generally needs all three.

What are the parts of big five?

Big five includes move constructor.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.