On this page
  1. References & Rvalues (& / &&)
  2. Overview
  3. Reference Kinds
  4. Gotchas

References & Rvalues (& / &&)

Prev: constexpr & consteval | Up: builtins | Next: RAII & Destructors
Rel: Move Semantics, Value Categories & Move Semantics, nullptr
Ref: cppreference — Reference Declaration
Tags: #public #prog #cpp #builtins #tier/core


Overview

A C++ lvalue reference (T&) is a non-null, non-reseatable alias to an existing object. An rvalue reference (T&&) binds to temporaries or explicitly moved objects, enabling move constructors and move assignment.

Reference Kinds

Syntax Binds To Typical Use
T& Mutable lvalues Out-parameters, mutating existing objects
const T& Lvalues and temporaries (rvalues) Read-only borrowing without copying
T&& Rvalues (temporaries, std::move(x)) Move constructors, sinks that steal resources
T&& (deduced template param) Any value category (forwarding reference) Perfect forwarding via std::forward<T>(x)

Gotchas

Linked from

Related notes