C++ 23 · Classes, memory and templates

Capture variables in a lambda

Capture by value with [=] or by reference with [&], or name what you need.

int factor = 3;
auto times = [factor](int n) { return n * factor; };

Official C++ 23 documentation

More classes, memory and templates commands

All classes, memory and templates commands · C++ 23 cheatsheet

Was this page helpful?