0Pricing
C++ Academy · Lesson

Lambda Captures by-value by-reference mutable

Choose capture clauses thoughtfully and understand lambda state.

Captures Recap

A lambda s capture clause lists variables from the surrounding scope it can use. The capture mode controls how each variable is accessed.

Capture by Value

Names listed without & are copied at lambda creation. The lambda owns its copy.

int n = 5;
auto f = [n]() { return n * 2; };
n = 10;
std::cout << f();   // 10 (captured n was 5)

All lessons in this course

  1. Function Objects Functors
  2. Lambda Captures by-value by-reference mutable
  3. Generic Lambdas and Closures C++14
  4. std::function Type-erased Callables
← Back to C++ Academy