title: Type-casting to an abstract class?
body: <p>I'm writing an event-based messaging system to be used between the various singleton managers in my game project.  Every manager type (InputManager, AudioManager, etc) is derived from a base Manager class and also inherits from an EventHandler class to facilitate message processing, as follows:</p>
  
  <pre><code>class Manager
  { ... }
  
  class EventHandler
  { ...
      virtual void onEvent(Event&amp; e) =0;
    ...
  }
  
  class InputManager : public Manager, public EventHandler
  { ... 
      virtual void InputManager::onEvent(Event&amp; e);
      { ... }
  }
  </code></pre>
  
  <p>Elsewhere I have an EventManager that keeps track of all EventHandlers and is used for broadcasting events to multiple recievers.  </p>
  
  <pre><code>class EventManager
  {...
      addHandlerToGroup(EventHandler&amp; eh);
      { ... } 
   ...
  }
  </code></pre>
  
  <p>Naturally when I'm initializing all of my singleton Managers, I want to be adding them as they're created to the EventManager's list.  My problem is that MVC++ complains at compile-time (and as I'm coding with squiggly lines) whenever I attempt to cast my Managers to EventHandlers.  I thought it would work as follows:</p>
  
  <pre><code>int main()
  { ...
      EventManager* eventM = new EventManager();
  
      ...
  
      InputManager* inputM = new InputManager();
      eventM-&gt;addHandlerToGroup(dynamic_cast&lt;EventHandler&gt;(inputM));
  
  } 
  </code></pre>
  
  <p>The compiler, however, informs me that "a cast to abstract class is not allowed."  I was under the impression that you can...after all, polymorphism doesn't do you much good without passing objects back and forth with a bit of flexibility as to how close to the base class they are interpreted.  My current workaround looks like this:</p>
  
  <pre><code>int main()
  { ...
      EventManager* eventM = new EventManager();
      EventHandler* temp;
  
      ...
  
      InputManager* inputM = new InputManager();
      temp = inputM;
      eventM-&gt;addHandlerToGroup(*inputM);
  
  } 
  </code></pre>
  
  <p>Which, as far as I can tell, is the same conceptually for what I'm trying to accomplish, if a bit more verbose and less intuitive.  Am I completely off as far as how typecasting with polymorphism works?  Where am I going wrong?</p>