Skip to content

Instantly share code, notes, and snippets.

@clangpp
Last active August 29, 2015 14:08
Show Gist options
  • Save clangpp/ed9a4448b2aca8f2461b to your computer and use it in GitHub Desktop.
Save clangpp/ed9a4448b2aca8f2461b to your computer and use it in GitHub Desktop.
void test6() {
int value = 1;
function<void()> f = [&value]() { value += 1; };
cout << value << endl; // 1
f();
cout << value << endl; // 2
f();
cout << value << endl; // 3
class TestLambda {
public:
int value = 10;
void Increase() {
function<void()> g = [this]() { this->value += 10; };
cout << value << endl; // 10
g();
cout << value << endl; // 20
g();
cout << value << endl; // 30
}
};
TestLambda test_lambda;
test_lambda.Increase();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment