   [C++] Member-function pointer from within a class passed to another class
  Hello. I am trying to do some deep wizardry and I can't seem to find a solid answer on how to accomplish my goal. I want to make a function pointer from within a class to its instance of the function and insert the pointer into a std::map.Say I have this classclass CInputManager{public:void KeyDownHd(WPARAM w, LPARAM l){WCHAR wc[] = {w, 0};MessageBox(NULL, wc, L"WM_KEYDOWN", NULL);}void AttachWindow(CWindow *window){window->RegisterHandler(WM_KEYDOWN, this->*KeyDownHd); // How do I do this?}};This is just a test but I would like to somehow get the address of KeyDownHd and pass it to RegisterHandler. This function is defined like so:void CWindow::RegisterHandler(UINT handle, void (*func)(WPARAM, LPARAM)){// Set handler to func in the handle map.m_handleMap[handle] = func;}I've tried everything I could think of and have been banging my head over this concept for a while now. I'm sure this is no simple task, but to know how to do this would be appreciated. If it's not possible I will rethink my design.Thank you for your time.   
  You'll want to use a combination of boost::function and boost::bind.This is just off the top of my head, consult the documentation for a real example:class CInputManager{public:  void KeyDownHd(WPARAM w, LPARAM l)  {    // ...  }  void AttachWindow(CWindow *window)  {    window->RegisterHandler(WM_KEYDOWN, boost::bind(&CInputManager::KeyDownHd, this, _1, _2));  }}// ....void CWindow::RegisterHandler(UINT wm, boost::function<void (WPARAM, LPARAM)> func){    m_handleMap[wm] = func;};  The most important thing you're missing is that in order to call a function on an object (in this case an instance of CInputManager) you will also need to store a pointer to the object. See:http://www.parashift.com/c++-faq-lite/pointers-to-members.html for more information.Like Codeka said, you should probably also take a look at boost::function.   ;  I really wanted to stay away from Boost, but after seeing Codeka's simple implementation I decided to cave and try it: and it works nicely! Thanks for the help guys; I will look more into Boost in the future.   ;  Given that you're obviously writing Windows-specific code, you might consider just using C#. Boosts Function and Bind libraries are very clever, but they ultimately not a patch on C# delegates.   ;  ChaosEngine, given that you do not know the context of this application, you cannot make assumptions that one language will be better than another. It is also beside the point seeing as my question has already been answered and I have already moved on to the next set of goals. Thank you for your concern, though.   ;  *shrug*Fair enough. Was just making you aware of your options. 