fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. class ClassXY
  5. {
  6. std::function<void()> function;
  7.  
  8. public:
  9. ClassXY(std::function<void()> f)
  10. : function(f)
  11. {}
  12.  
  13. void call()
  14. {
  15. function(); // Calls the function
  16. }
  17. };
  18.  
  19. class Handler
  20. {
  21. public:
  22. void HandleButtonEvent()
  23. {
  24. std::cout << "Handler::HandleButtonEvent\n";
  25. }
  26. };
  27.  
  28. int main()
  29. {
  30. Handler* handler = new Handler;
  31.  
  32. ClassXY xy(std::bind(&Handler::HandleButtonEvent, handler));
  33.  
  34. xy.call();
  35. }
  36.  
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Handler::HandleButtonEvent