• Advertisement
Sign in to follow this  

Member Function Pointers

This topic is 3162 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ugh... im trying to wrap my head around this. Basically my engine had extern items that, for the sake of architecture, were brought into their respective classes. The problem is... some of those extern items were function pointers... thus making them.. member function pointers. And now another class is trying to dereference that member function pointer. What was a nice clean line of code now is broken.. and i am trying to figure out how to fix it... here is the issue in pseudo code.
class EngineManager {
KeyboardAndMouse *Input;
Console *gameConsole;
//End EngineManager

class Console;

typedef void(Console::*keystrokecallback)(char); //doesnt work

class KeyboardAndMouse {

 vector <keystrokecallback> keyCallBackList;
//end input.h

//console class
class Console{
   void keyboardReactor(char c);
//end console class

//EngineManager.cpp calls this guy
Input->keyCallbackList.push_back( &Console::keyboardReactor );

Any ideas? Thanks in advance.

Share this post

Link to post
Share on other sites
Check out boost::function and boost::bind. They will let you bind a member function pointer to an instance, and then call it like a free function. The sample code has more details, plus this has come up many times before in the forums so you can Google for other threads.

Share this post

Link to post
Share on other sites
Cool, thanks guys.
I may be stubborn/naive but for now I am avoiding boost.

Original post by Driv3MeFar
Read me.

Edit: link fixed.

I think i see what my problem is ... i need to have the object instance and use that macro-ish thing in the faq

#define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember))

to make it readable

the syntax on the right is what i dont have.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement