Skip to content

Instantly share code, notes, and snippets.

Created February 26, 2013 01:09
Show Gist options
  • Save anonymous/5034882 to your computer and use it in GitHub Desktop.
Save anonymous/5034882 to your computer and use it in GitHub Desktop.
Fail closure
#include <memory>
#include <iostream>
using namespace std;
typedef function<void(int)> func;
shared_ptr<func> create_lambda() {
return make_shared<func>([]() {
int tmp;
return [&tmp](int c) {
cout << tmp++ << endl;
};
}());
}
int main(void) {
shared_ptr<func> normal(create_lambda());
(*normal)(1);
(*normal)(2);
(*normal)(5);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment