Member Function Pointers

Started by
2 comments, last by AverageJoeSSU 14 years, 9 months ago
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 );


Any ideas? Thanks in advance.

------------------------------

redwoodpixel.com

Advertisement
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.
Read me.

Edit: link fixed.
Cool, thanks guys.
I may be stubborn/naive but for now I am avoiding boost.

Quote: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.

------------------------------

redwoodpixel.com

This topic is closed to new replies.

Advertisement