Copy and Move Semantics
Copy Constructors
A constructor that produces a new object as a copy of another object of the same type is called a copy constructor. If none is supplied by the programmer, the c…
Copy Assignment Operators
Copy construction means creating a new object based on another. Copy assignment takes two existing objects and sets the left hand side object to have the same v…
Shallow and Deep Copying
If a class has only "normal" values in it, such as integers or floating point values, then the copy constructor and copy assignment operator provided by the com…
The Rule of Three
When a class has only fundamental types as data members, you usually don't need to write your own destructor, copy constructor, or copy-assignment operator beca…
Move Constructors
A move constructor initializes a new object with the internals of another object that is about to go out of scope. Instead of copying the members, the move cons…
Move Assignment Operators
The move assignment takes an object about to die and copies its values into an existing object. The object on the lhs isn't created and is simply overwritten. T…
std::move
std::move doesn't do any moving itself. It's a cast that converts an lvalue to an rvalue reference, which makes a move constructor or move-assignment operator a…
The Rule of Five
When a class handles a resource that the compiler can't properly copy or destroy by itself, the five special member functions are no longer optional. They becom…
The Rule of Zero
Most classes never need to be in a position to write a destructor, copy constructor, copy assignment operator, move constructor, or move assignment operator. If…