fork download
  1. #include <functional>
  2. #include <iostream>
  3. #include <memory>
  4.  
  5. class AAA {};
  6. class BBB {};
  7.  
  8. class Notifier
  9. {
  10. public:
  11. Notifier(std::function<void(AAA&, BBB&)> on_notify)
  12. :on_notify_(on_notify)
  13. { }
  14.  
  15. void notify()
  16. {
  17. if (on_notify_)
  18. {
  19. AAA a{};
  20. BBB b{};
  21. on_notify_(a, b);
  22. }
  23. }
  24.  
  25. std::function<void(AAA&, BBB&)> on_notify_;
  26. };
  27.  
  28. struct Manager
  29. {
  30. Manager()
  31. {
  32. n_ = std::make_unique<Notifier>(std::bind(&Manager::trigger, this));
  33. }
  34.  
  35. void trigger()
  36. {
  37. std::cout << "it's also notified!" << std::endl;
  38. }
  39.  
  40. std::unique_ptr<Notifier> n_;
  41. };
  42.  
  43. int main()
  44. {
  45. Manager s;
  46. s.n_->notify();
  47. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
it's also notified!