fork(1) download
  1. #include <iostream>
  2. #include <functional>
  3. using namespace std;
  4.  
  5.  
  6.  
  7. function<void()>* preparatory_work() {
  8. auto l = [](){ cout<< "My lambda is fine !" <<endl; } ; // lambda
  9. function<void ()> f = l; // functor
  10. auto p = new function<void()>(l); // a functor on the heap
  11.  
  12. l(); // inovke the lambda object
  13. f(); // invoke the functor
  14. (*p)(); // invoke functor via a pointer
  15.  
  16. return p;
  17. }
  18.  
  19. int main() {
  20. auto fcp = preparatory_work();
  21. (*fcp)();
  22. void *x = (void*)fcp;
  23. (*(function<void()>*)x)();
  24.  
  25. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
My lambda is fine !
My lambda is fine !
My lambda is fine !
My lambda is fine !
My lambda is fine !