title: C++ system for passing events with inheritance hierarchy
body: <p>I am currently programming an event passing system for a game in C++ and I thought it would be useful if the events inherited from each other in a logical way. </p>
  
  <p>This means I could for example raise an event of type <code>NukeExplosion</code>, which derives from <code>Explosion</code> (which would probably derive from an empty base class <code>Event</code>) and it would get passed to all listeners to an event of type <code>NukeExplosion</code>, as well as the more generic <code>Explosion</code>.</p>
  
  <p>So far I was able to come up with two possible solutions:</p>
  
  <ul>
  <li>Doing a <code>dynamic_cast</code> on the event for each set of listeners to the same event type. If it succeeds, I can then pass the event to all the listeners in the set.</li>
  <li>Adding a piece of code to each Event type which raises the event again, but with a more generic type. The event would then be passed to listeners using the result of the <code>typeid</code> operator in conjunction with a map of listeners.</li>
  </ul>
  
  <p>I don't really like the second option, because it's error-prone, and requires me to write almost the same code in every event class. </p>
  
  <p>The problem with the first option is that it might need to do a lot of <code>dynamic_cast</code>s, and I would like to avoid that.</p>
  
  <p>So, is there any other way which I haven't taken into accont, or is the first option the best I can do? Or should I completely drop the inheritance of events?</p>