   Function Pointers
  I'm trying to create a function pointer so that I can set it to whatever function I want during the code and then simply call the function pointer when i want to call the function. I'm having a little trouble in trying to set it up though. This is basically what I have so far:-Character.hclass Character{public:Character(void);~Character(void);//All the other funcitonsvoid Sleep();private:void (*pDecisionFunciton)(void);//All the other variables};Character.cpppDecisionFunciton = &Sleep;This is giving me the compile error : error C2276: '&' : illegal operation on bound member function expressionFrom the website I've been looking at this synatax is correct, but then again the website I've been looking at havent used them in classes...is this the correct way to be going about it?   
  A pointer to a member function is not a function pointer.   ;  Can you explain the differance then please? Or direct me to a website that can?   ;  If I remember correctly, you need to do something like: pDecisionFunciton = &Character::Sleep;;Quote:Original post by ScottH87Can you explain the differance then please? Or direct me to a website that can?The page Bregma linked to will tell you. Basically a member function has a hidden "this" pointer.Quote:Original post by K1nG Gr4H4mIf I remember correctly, you need to do something like: pDecisionFunciton = &Character::Sleep;Only if it's a static member function in another class.   ;Quote:Original post by ScottH87Can you explain the differance then please? Or direct me to a website that can?Did you even read the link Bregma gave?  Did you try google?  This was the third result for this search.  Bregma's link is a must read though.   ;  Ok I read Bregmas link, but I'm still having some issues when it comes to setting the address of the pointer.This is what I have now:-Character.h#define CALL_MEMBER_FUNC(object,ptrToMember)  ((object).*(ptrToMember)) class Character{public:Character(void);~Character(void);//All the other funcitonsvoid Sleep();private://All the other variables};typedef void (Character::*MemberFunctionPointer)(void)  const;Character.cppMemberFunctionPointer pDecisionFunciton;pDecisionFunciton = &Sleep;And still getting the error: error C2276: '&' : illegal operation on bound member function expressionIs there something that I'm missing?   ;Quote:Original post by ScottH87Ok I read Bregmas link, but I'm still having some issues when it comes to setting the address of the pointer.This is what I have now:-Character.h*** Source Snippet Removed ***Character.cpp*** Source Snippet Removed ***And still getting the error*** Source Snippet Removed ***Is there something that I'm missing?What about doing it without the & ? (I forget the exact syntax for member function pointers offhand).And is the code in "Character.cpp" in a member function of the class?   ;  It still doesnt work without the address operator and yeah the code I gave in Character.cpp is in a member function of the Character class   ;  Try:pDecisionFunciton = &Character::Sleep;This is what I typically use. 