Skip to content

Instantly share code, notes, and snippets.

@joseph-montanez
Created June 6, 2011 22:55
Show Gist options
  • Save joseph-montanez/1011298 to your computer and use it in GitHub Desktop.
Save joseph-montanez/1011298 to your computer and use it in GitHub Desktop.
lamdba Example
#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