What is wrong with the syntax here? I follow this resource.
char x = 'a', y = 'a';
[&x,=y]() { // error: expected identifier before '=' token
++x; ++y; // error: 'y' is not captured
}();
I use MinGW g++ 4.5.2 command line compiler with -std=c++0x
clarification: I’d like to pass y by value.
Live example.
Is the correct code. To capture a variably by-value, just write its name. To allow modification of by-value captures, the lambda needs to be marked
mutable, otherwise theoperator()is markedconst.§5.1.2 [expr.prim.lambda] p5