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