|
-
Feb 2nd, 2006, 05:56 PM
#1
Thread Starter
PowerPoster
Member Function Pointer Mayham
EDIT: Skip this and read my reply. It gives a much more clear scenerio.
I need to make use of a function pointer to a member function. I am running into many issue's with this.
The problem is I am trying to store a function pointer which is a member of class 'State' but I am passing in a function from class 'GameState' which derives from 'State'.
Here is the snippets to best describe my dilema:
PHP Code:
//An abstract State class which contains this virtual method
/**
* Handles messages for the gameWindow
*/
virtual LRESULT CALLBACK messageHandlerWindow(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) = 0;
//Here is a class which derives from the State class and overrides the method
/**
* Handles messages for the gameWindow
*/
LRESULT CALLBACK GameState::messageHandlerWindow(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
//Here is a GraphicLayer class which needs to be able to
//take in a function pointer to its messageHandlerWindow(..)
//This messageHandler has to be generic because there are more states
//than just the gameState seen above.
//Member in GraphicLayer to store the func pointer
//non-static State specific message handler
LRESULT (__stdcall State::*m_pMsgHandler)(HWND, UINT, WPARAM, LPARAM);
/**
* Attach a STATE specific message handler to the window
* The static message handler does nothing but pass its messages to this
* @param msgHandler - A function pointer to the msgHandler
*/
void GraphicLayer::attachWindowMessageHandler(LRESULT (__stdcall State::*msgHandler)(HWND, UINT, WPARAM, LPARAM))
{
m_pMsgHandler = msgHandler;
}
The errors I get just keep running me in circles.
error C2664: 'GraphicLayer::attachWindowMessageHandler' : cannot convert parameter 1 from 'LRESULT (__stdcall GameState::* )(HWND,UINT,WPARAM,LPARAM)' to 'LRESULT (__stdcall State::* )(HWND,UINT,WPARAM,LPARAM)'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Also, how would I write the return for that... It seems rather complex:
PHP Code:
/**
* Returns the message handler which was attached to the graphicLayer
* @return msgHandler - The pointer attached to the graphic layer
*/
LRESULT (__stdcall State::*GraphicLayer::getAttachedWindowMessageHandler())(HWND, UINT, WPARAM, LPARAM)
{
return m_pMsgHandler;
}
Last edited by Halsafar; Feb 2nd, 2006 at 06:19 PM.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|