fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4.  
  5. class EventListener
  6. {
  7. public:
  8. void test(int n)
  9. {
  10. std::cout << "n is: " << n << std::endl;
  11. }
  12. };
  13.  
  14. typedef void (EventListener::*ftOnEventClass)(int n);
  15.  
  16. struct EventNode
  17. {
  18. ftOnEventClass functionClass;
  19. EventListener* handle;
  20. };
  21.  
  22.  
  23. int main()
  24. {
  25. std::vector<EventNode *> m_vEventHandlerList;
  26. EventListener el;
  27. EventNode en = { &EventListener::test, &el};
  28. m_vEventHandlerList.push_back(&en);
  29.  
  30. for (auto& iter : m_vEventHandlerList)
  31. {
  32. if (iter->handle != nullptr)
  33. {
  34. (iter->handle->*iter->functionClass)(123);
  35. }
  36. }
  37. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
n is: 123