fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <queue>
  4.  
  5. class Event {
  6. public:
  7. std::string name;
  8. Event(const std::string &name_) :name(name_) {}
  9. };
  10.  
  11. class KeyEvent : public Event {
  12. public:
  13. int key;
  14. KeyEvent(const std::string &name_, int key_) : Event(name_), key(key_) {}
  15. };
  16.  
  17. int main() {
  18. std::queue<Event> eventsQueue;
  19. eventsQueue.push(KeyEvent("keyPress", 16));
  20. eventsQueue.push(Event("randomEvent"));
  21.  
  22. while(!eventsQueue.empty()) {
  23. auto &e = eventsQueue.front();
  24. std::cout << e.name;
  25. if(e.name == "keyPress") {
  26. std::cout << ": " << static_cast<KeyEvent &>(e).key;
  27. }
  28. eventsQueue.pop();
  29. std::cout << std::endl;
  30. }
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
keyPress: 166580876
randomEvent