Last active
August 29, 2015 14:08
-
-
Save clangpp/ed9a4448b2aca8f2461b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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