Member Function Pointers

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.
//EngineManager.h
class EngineManager {
private:
KeyboardAndMouse *Input;
Console *gameConsole;
};
//End EngineManager

//Input.h
class Console;

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

class KeyboardAndMouse {

public:
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 );



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 on other sites
Cool, thanks guys.
I may be stubborn/naive but for now I am avoiding boost.

Quote:

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))

the syntax on the right is what i dont have.

Create an account

Register a new account

• Forum Statistics

• Total Topics
628277
• Total Posts
2981770

• 10
• 11
• 17
• 10
• 9