Say we have Class A:
class A
{
double x;
double y;
A(double, double);
function <double(void)> F;
};
And the following constructor:
A::A(double a, double b)
{
x = a;
y = b;
F = [this]() { return x + y; };
}
Why does the above constructor work while the following constructor causes a compilation error: member A::x is not a variable
? (Same error for y
.)
A::A(double a, double b)
{
x = a;
y = b;
F = [x,y]() { return x + y; };
}
It seems I can capture only this
and not the class members. Why is that?