fork download
  1.  
  2. #include <functional>
  3. #include <iostream>
  4. #include <string>
  5.  
  6. struct net
  7. {
  8. void work()
  9. {
  10. std::cout << "net: working...\n";
  11. if(this->onEvent)
  12. this->onEvent("access is allowed");
  13. }
  14.  
  15. std::function<void(const std::string&)>
  16. onEvent;
  17. };
  18.  
  19.  
  20. int main()
  21. {
  22. const auto reaction = [](const auto& answer){
  23. std::cout << "event: " << answer << '\n';
  24. };
  25.  
  26.  
  27. net agent;
  28. agent.onEvent = reaction;
  29. agent.work();
  30. }
Success #stdin #stdout 0s 4564KB
stdin
Standard input is empty
stdout
net: working...
event: access is allowed