Category

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…

Jul 15, 2026 →

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…

Jul 15, 2026 →

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…

Jul 15, 2026 →

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…

Jul 15, 2026 →

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…

Jul 15, 2026 →

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…

Jul 15, 2026 →

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…

Jul 15, 2026 →

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…

Jul 15, 2026 →

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…

Jul 15, 2026 →
About CppLearn

CppLearn is an interactive, free reference for modern C++. In each lesson, you'll find out how the language works, rather than just lines of code that you can copy and paste. We cover concepts starting from beginner lessons on fundamentals and proceed to templates, move semantics, smart pointers, and areas that usually trap or scare C++ learners.