c++ - Polymorphic member function pointer -


I am trying to write a callback event system in DirectX9. I am trying to use method function signals to trigger events for mouseclick; But I'm having some problems My game uses a gamestate manager to manage the rendering All my gamestates are taken from the base class abstractGameState

I have a phantom object with this specific method:

  m_NewGameSprite-> OnClick (this, and menmanustat :: start the game);  

The main menu is the current game that is in my game, and StartGame is a void method part of this class. I want to store the function pointer in a variable within my phantom class so that users can click.

  template & lt; Typename T & gt; Zero onclick (GameState * LinkedState, Zero (T :: * Event Pointer) ()) {m_LinkedGameState = LinkedState; M_EventPointer = Event indicator; // & lt; - does not compile}  

I tried to downconver the indicator, but it does not really work.

These include two variables in my Prayer class

  Zero (GameState :: * m_EventPointer) (); GameState * m_LinkedGameState;  

Any help would be appreciated

I'm not really Know why your work is not going on, there is no doubt why it will be clear why a beautiful, normal, typewrif and standard function object that in almost all the circumstances is the replacement for function pointer Can be used. I will do this:

  typedef boost :: function0  

Note that event class now includes the status of the function call, with the object you want to call it. Generally you also use to create a closer, but you can easily tie a free function or any other function object.

  Zero OnClick (events and events) {m_Event = event; }  

Call it like this:

  OnClick (boost :: bind (& MainMenuState :: StartGame, this));  

With this scheme, you do not really need to store "linked game state" - this is explained in the event object.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -