I am learning c++11 new function lambda function and am a little confused. I read that
[] Capture nothing (or, a scorched earth strategy?)
[&] Capture any referenced variable by reference
[=] Capture any referenced variable by making a copy
[=, &foo] Capture any referenced variable by making a copy, but capture variable foo by reference
[bar] Capture bar by making a copy; don't copy anything else
[this] Capture the this pointer of the enclosing class
My question is what exactly does capture a variable mean and what's the difference with return a value, if you want to capture a variable you have to return it right?
For example:
[] () { int a = 2; return a; }
Why is it not
int [] () { int a = 2; return a; }