Is there a way, when writing a lambda function within a member function, to capture fields of the enclosing class by value? The default catch-all = doesn\'t work be
=
Yes, simply write the [=] construct. For instance:
[=]
class MyClass { int a; void foo() { auto my_lambda = [a_by_val=a] { // do something with a_by_val } my_lambda(); } }