0Pricing
C++ Academy · Lesson

Rvalue References and the && Syntax

Bind to temporaries with rvalue references for efficient resource transfer.

The && Syntax

An rvalue reference is declared with T&&. It binds only to rvalues — temporaries about to die.

int&& ref = 42;          // OK: binds to literal
int x = 10;
// int&& bad = x;        // ERROR: x is an lvalue

Why Have rvalue References?

They let you write functions that know the argument is about to be destroyed. You can take its resources without making a copy.

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