fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. class C
  5. {
  6. public:
  7. void func() { std::cout << "I'm C::func()" << std::endl; }
  8. };
  9.  
  10. typedef void (C::*ptrFunc)();
  11.  
  12. void call1(C* pC, ptrFunc f)
  13. {
  14. (pC->*f)();
  15. }
  16.  
  17. void call2(std::function<void()> f)
  18. {
  19. f();
  20. }
  21.  
  22. int main()
  23. {
  24. C c;
  25. call1(&c, &C::func);
  26. call2(std::bind(&C::func, &c));
  27. call2([&c]() { c.func(); });
  28. return 0;
  29. }
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
I'm C::func()
I'm C::func()
I'm C::func()