I would like some clarification on lambda.
In the code below, I thought that using "mutable" will let me modify the captured variables. But the lambda function f2() doesn't seem to work that way.
Is the code below wrong? If it does, shouldn't there be a compile error?
Code:int x = 1; int y = 50; int z = 3; auto f2 = [=] () mutable {++x ;return x+y+z;}; std::cout << "f2() = " << f2() << std::endl; // print 55 std::cout << "x = " << x << std::endl; // print 1