fork(2) download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. class Foo
  5. {
  6. int x, y, z;
  7. std::function<void(void)> _func;
  8.  
  9. public:
  10. Foo(int a): x(a), y(0), z(0) {}
  11.  
  12. void bar()
  13. {
  14. int a = 1,b,c;
  15. _func = [=]()
  16. {
  17. int u = this->x + a;
  18. std::cout << u << std::endl;
  19. };
  20.  
  21. _func(); // lambda call
  22. }
  23. };
  24.  
  25. int main()
  26. {
  27. Foo obj(1);
  28. obj.bar();
  29. }
Success #stdin #stdout 0s 4540KB
stdin
Standard input is empty
stdout
2