title: Creating a Event Management System SDL2
body: <p>I have created game in Python with pygame. Now I want to port this game to c++ using SDL2. In the python build of this game there was a sort of event manager system. A class that read the event queue then stored these events in a list so they could be checked multiple times during game loop. The event manager would reset this copy of the event queue and update to the new events. It looks like this:</p>
  <pre><code>class EventHandler:
  
      def __init__(self, w, h):
          self.event_list = pygame.event.get()
          self.width, self.height = w, h
          self.window = pygame.display.set_mode((self.width, self.height), pygame.RESIZABLE)
  
      def update(self):
          self.event_list = pygame.event.get()
  
      def handle(self):
          for event in self.event_list:
              if event.type == pygame.QUIT:
                  pygame.quit()
                  quit()
              if event.type == pygame.VIDEORESIZE:
                  self.width, self.height = event.w, event.h
                  self.window = pygame.display.set_mode((self.width, self.height), pygame.RESIZABLE)
          self.update()
  
      def search(self, eventName): # SEARCH FOR AN EVENT IN THE EVENT QUEUE
          for event in self.event_list:
              if event.type == eventName:
                  return True
              else:
                  return False
  </code></pre>
  <p>This a a very simplified version of the event manager class I was using in the python game. I created a copy if the event queue because pygame removes the events from the queue after you have checked the queue for it once. This makes it extremely difficult to detect these event later on in the loop, this is why I created a copy of the event queue to check for events multiple times in the same loop.</p>
  <p>How would I be able to copy or add all events needed to a similar data structure of a list such as a vector or std::list in c++. So far this is what I have:</p>
  <p>python
  class EventHandler
  {
  public:
  bool quit;
  SDL_Event event;
  SDL_Window* window;
  SDL_Renderer* render;</p>
  <pre><code>    int width;
      int height;
  
      std::string keyEvents;
  
      //mouse state
      int mouseX, mouseY;
      
      EventHandler()
      {
          //Iniliaze SDL
          if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
              std::cout &lt;&lt; &quot;SDL Error: &quot; &lt;&lt; SDL_GetError();
          }
          TTF_Init();
          window = SDL_CreateWindow(&quot;Fallen Planets&quot;, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1024, 1080, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
          if (window == NULL){
              std::cout &lt;&lt; &quot;SDL Error: &quot; &lt;&lt; SDL_GetError();
              SDL_Quit();
              quit = true;
          }
          render = SDL_CreateRenderer(window, -1, 0);
          if (render == NULL){
              SDL_DestroyWindow(window);
              std::cout &lt;&lt; &quot;SDL Error: &quot; &lt;&lt; SDL_GetError();
              SDL_Quit();
          }
  
          //initialise SDL_Image
          IMG_Init(IMG_INIT_PNG);
  
          //Initialize quit bool
          quit = false;
  
          //Get default screen res
          SDL_GetWindowSize(window, &amp;width, &amp;height);
  
      }
  
      void handle(){
          while (SDL_PollEvent(&amp;event)){
              if (event.type == SDL_QUIT){
                  SDL_DestroyWindow(window);
                  SDL_DestroyRenderer(render);
                  TTF_Quit();
                  SDL_Quit();
                  quit = true;
              }
              if (event.window.event == SDL_WINDOWEVENT_RESIZED){
                  width = SDL_GetWindowSurface(window)-&gt;w;
                  height = SDL_GetWindowSurface(window)-&gt;h;
  
              }
              if (SDL_MOUSEBUTTONDOWN){
                  if (event.button.button ==  SDL_BUTTON_LEFT){
                      keyEvents = &quot;MOUSEBUTTON_LEFT&quot;;
                  }
              }
              //Update Mouse State
              SDL_GetMouseState(&amp;mouseX, &amp;mouseY);
          }
          //SDL_RenderPresent(render);
      }
  };
  </code></pre>
  <p>Once I have added these events to a vector, I use this code to check the evnts. However I get varying erros from this.</p>
  <pre><code>    for (std::vector&lt;SDL_Event&gt;::const_iterator i = eventObject.eventList.begin(); i != eventObject.eventList.end(); ++i){
          if (*i == SDL_KEYDOWN){
              std::cout &lt;&lt; &quot;key pressed\n&quot;;
          }
      }
  </code></pre>
  <p>In the above code I get this error: No operator matches const SDL-Event == SDL-EventType. Removing * from the code gives me this error: No operator matches SDL_Event &amp; == SDL_EventType. What would I be doing wrong to check for key events?</p>