fork download
  1. #include <functional>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. const function<void()>* pointer;
  6.  
  7. void a(const function<void()> & f)
  8. {
  9. pointer = &f;
  10. }
  11.  
  12. void b()
  13. {
  14. (*pointer)();
  15. }
  16.  
  17. int main()
  18. {
  19. int value = 1;
  20. std::cout << value << std::endl;
  21.  
  22. // 1: this works
  23. function<void()> f = [&] () { std::cout << value << std::endl; };
  24. a(f);
  25.  
  26. // 2: this doesn't
  27. a([&] () { std::cout << value << std::endl; });
  28. //c();
  29. char data[1024];
  30. for (int i = 0; i < 1024; i++)
  31. data[i] = i % 4;
  32.  
  33. b();
  34.  
  35. return 0;
  36. }
Runtime error #stdin #stdout 0s 3016KB
stdin
Standard input is empty
stdout
1