http://coliru.stacked-crooked.com/a/29520ad225ced72d
#include <iostream>
struct S
{
void f()
{
//auto f0 = [] { ++i; }; // error: 'this' was not captured for this lambda function
auto f1 = [this] { ++i; };
auto f2 = [&] { ++i; };
auto f3 = [=] { ++i; };
f1();
f2();
f3();
}
int i = 10;
};
int main()
{
S s;
std::cout << "Before " << s.i << std::endl;
s.f();
std::cout << "After " << s.i << std::endl;
}
Before 10
After 13
Question: Why does [=]
enable modification of member variables in a lambda?