Quick A: [x] captures a copy, [&x] remembers a reference to the original variable.
C++ Lambdas: Difference between “mutable” and capture-by-reference
In C++ you can declare lambdas for example like this:
int x = 5; auto a = [=]() mutable { ++x; std::cout << x << '\n'; }; auto b = [&]() { ++x; std::cout << x << '\n'; };Both let me modify
x
, so what is the difference?
Add a Comment
Comments are closed.