Search⌘ K
AI Features

Copy and Move Constructors

In this lesson, you will learn about two types of constructors: copy and move.

Copy constructor

A copy constructor is a special member function with the following signature:

ClassName(const ClassName&);

It’s used when you create an object using a variable of the same type. For example:

Experiment exp { 42, 100 };
Experiment other { exp }; // copy constructor called!

Implementing a copy constructor might be necessary when your class has data members that cannot be shallow copied, like ...