C++ callback system
<p>I'm trying to make a simple event dispatcher system. To put it simply, I have event classes that all derive a IEvent interface. I also have an EventManager class with a couple of methods:</p>

<pre><code>void    addListener( int eventID, std::function&lt;void( IEvent *event )&gt; callback );
void    dispatchEvent( int eventID, IEvent *event );
</code></pre>

<p>The EventManager has a map of vectors:</p>

<pre><code>std::map&lt;int, std::vector&lt;std::function&lt;void( IEvent * )&gt; &gt; &gt;   m_events;
</code></pre>

<p>Any object can then register via the addListener method, giving it a callback, and it will be notified whenever someone calls dispatchEvent with the same event type:</p>

<pre><code>// add an event listener
EventManager::addListener(Event_MouseMove, std::bind(&amp;Obj::callback, this, std::placeholders::_1));

// the callback method
void Obj::callback( IEvent *e )
{
    // here I need to cast e to a MouseEvent *
    // I want to get rid of this.
    MouseEvent *me = (MouseEvent *)e;
}
</code></pre>

<p>When calling dispatchEvent, the caller must pass an IEvent derived class, MouseEvent for example:</p>

<pre><code>// dispatching an Event
EventManager::dispatchEvent(Event_MouseMove, new MouseEvent());
</code></pre>

<p>My problem has to do with the callback method.
Say you want to listen for a MouseEvent, the object would have a method like such:</p>

<pre><code>void    eventHandler( MouseEvent *event );
</code></pre>

<p>The problem is that the callback can not be passed to the addListener method as it is expecting an IEvent * and not a MouseEvent *. To make it work, I just use IEvent types and then the event handler method must cast that IEvent * to the derived type it is expecting; in this case a MouseEvent *.
How can I make it that the addListener method take a pointer to a method that will receive any IEvent derived class ?</p>

<p>As an example:</p>

<pre><code>// add an event listener
EventManager::addListener(Event_MouseMove, std::bind(&amp;Obj::callback, this, std::placeholders::_1));

// the callback method
void Obj::callback( MouseEvent *e ) { ... }

// dispatching an Event
EventManager::dispatchEvent(Event_MouseMove, new MouseEvent());
</code></pre>
