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 this constructor work, and 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 only capture this , not the members of the class. Why is this?
c ++ lambda
Romansko
source share