Original Post
Hi
I was just wondering if you can have a pointer to a method in a class. I have created a gui with callback functions and wanted the callbacks I created to be part of my main game class. It only works though if I make them static.( not desired ). Is there way around this.
a sample of my code is:
//in my gui CoreComponent header
//this is my callback pointer
typedef void(*ComponentCallback)( CoreComponent * caller );
class CoreComponent
{
...
void SetEventCallback( EventType event, ComponentCallback callback );
...
};
//in global space
void testCallback( CoreComponent * caller )
{
...//some stuff here
}
//in game core
class GameCore
{
...
void callback( CoreComponent * caller );
...
}
void GameCore::Run()
{
CoreComponent c;
c.SetEventCallback( testCallback ); //this works fine
CoreComponent c2;
c2.SetEventCallback( this->callback ); //doesn''t work unless
//GameCore::callback //is static
}
Can I force this->callback above to be a vaild function pointer?
The error I get is something like:
cannot convert from void callback * to void (__cdecl) callback *
casting to (__cdecl) doesn''t work.
Any help is appreciated. Thanks.
Pete