fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. class Worker
  5. {
  6. std::function<void()> to_work;
  7. public:
  8. void work() const { to_work(); }
  9. Worker(std::function<void()> work_func ) : to_work(work_func) {}
  10. };
  11.  
  12. class Employer
  13. {
  14. public:
  15. void work_bitch(const Worker& w)
  16. {
  17. w.work();
  18. }
  19. };
  20.  
  21. int main()
  22. {
  23. Employer e;
  24.  
  25. e.work_bitch(Worker([]() { std::cout << "I'm working\n"; }));
  26. e.work_bitch(Worker([]() { std::cout << "I'm working too\n"; }));
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
I'm working
I'm working too