fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <functional>
  4. using namespace std;
  5.  
  6. struct Manager {
  7. string name;
  8. void timeCount(std::function<void(void)> f) {
  9. std::cout << "This is " << name << " manager" << endl;
  10. f();
  11. }
  12. };
  13.  
  14. void foo() {
  15. cout << "I'm foo" << endl;
  16. }
  17.  
  18. struct Test {
  19. int x;
  20. void bar() {
  21. cout << "I'm bar " << x << endl;
  22. }
  23. };
  24.  
  25. int main() {
  26. Manager mgr {"time"};
  27. mgr.timeCount(foo);
  28. Test tst = {234};
  29. mgr.timeCount(std::bind( &Test::bar, tst));
  30. return 0;
  31. }
Success #stdin #stdout 0s 4416KB
stdin
Standard input is empty
stdout
This is time manager
I'm foo
This is time manager
I'm bar 234