fork(8) download
  1. #include <functional>
  2.  
  3. std::function<int()> dowork()
  4. {
  5. int answer = 42;
  6. auto lambda = [answer] () { return answer; };
  7.  
  8. // can do what we want
  9. answer = 666;
  10. return lambda;
  11. }
  12.  
  13. int main()
  14. {
  15. auto ll = dowork();
  16. return ll(); // 42
  17. }
  18.  
Success #stdin #stdout 0s 2956KB
stdin
Standard input is empty
stdout
Standard output is empty