0Pricing
C++ Academy · Lesson

Move Constructors and Move Assignment

Implement move constructors and move assignment operators correctly.

Two Special Members

The move constructor and move assignment operator let your class take ownership of another instance s resources without copying.

Signature

Both take an rvalue reference to the same type.

class String {
public:
    String(String&& other) noexcept;          // move ctor
    String& operator=(String&& other) noexcept; // move assign
};

All lessons in this course

  1. Lvalue vs Rvalue The Distinction
  2. Rvalue References and the && Syntax
  3. std::move and std::forward
  4. Move Constructors and Move Assignment
← Back to C++ Academy