fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. auto makeWorker = []() {
  7. int X = 1;
  8. return [=]() mutable {return X++;};
  9. };
  10. auto worker = makeWorker();
  11. auto worker2 = makeWorker();
  12.  
  13. cout << worker() << endl;
  14. cout << worker2() << endl;
  15. cout << worker() << endl;
  16. cout << worker2() << endl;
  17.  
  18. return 0;
  19. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
1
1
2
2