functor accessing class members ?
Posted: May 16th, 2020, 8:23 pm
Hi there,
I just discover functors and I'd like to use them as functions into functions, to reduce the scope of these subfunctions, as little local swiss knifes. What I would like to do is something like this :
he says : "an enclosing-function local variable cannot be referenced in a lambda body unless if it is in capture list"
I cannot figure out what it means, but g cannot access A members ?
I just discover functors and I'd like to use them as functions into functions, to reduce the scope of these subfunctions, as little local swiss knifes. What I would like to do is something like this :
Code: Select all
class A
{
void f();
int x;
}
void A::f()
{
auto g = []()
{
x *= 2;
}
g();
}
I cannot figure out what it means, but g cannot access A members ?