Created
June 6, 2011 22:55
-
-
Save joseph-montanez/1011298 to your computer and use it in GitHub Desktop.
lamdba Example
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
#include <iostream> | |
int main (int argc, char *argv[]) { | |
int x = 42; | |
int y = 99; | |
auto lambda = [x, &y]() mutable { | |
x++; | |
// Because x is not referenced, it will never effect the global x | |
// however it will be effected inside this same lambda, so running it | |
// multiple times will result x incremenint, but not the global x | |
y++; | |
std::cout << x << ", " << y << "\n"; | |
}; | |
lambda(); | |
std::cout << x << ", " << y << "\n"; | |
lambda(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment