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