copy-capturing this with C++ lambdas
问题 Reading up on lambdas, I tried understanding them capturing this and *this . I wrote a small test: #include <iostream> #include <functional> using namespace std; struct A { int x = 0; function<int(void)> get_x_cpy = [=, this]() { return x++; }; function<int(void)> get_x_ref = [&, this]() { return x++; }; }; int main() { A a; cout << a.get_x_cpy() << a.get_x_cpy() << a.get_x_ref() << a.get_x_ref() << '\n'; } and, expecting the get_x_cpy() to make a copy of a I expected to see 0001 or 0101