Function pointer
Hi!
For some reason I am not able to create a pointer to a function. It should work like this, but VC6 won''t compile:
void CALLBACK CGameManager::ShowSplashScreen( float fPercent )
{
...
}
typedef void (APIENTRY * PFNPROGRESSBAR) (float fPercent);
PFNPROGRESSBAR UTIL_ProgressBar;
UTIL_ProgressBar = &CGameManager::ShowSplashScreen;
It aborts with the following message:
error C2440: ''='' : cannot convert from ''void (__stdcall CGameManager::*)(float)'' to ''void (__stdcall *)(float)''
Thanks for any response!
Hyperion
Either make the callback static, invent a clever way to pass it ''this'' pointer, or use someone else''s code to do (2).
---visit #directxdev on afternet <- not just for directx, despite the name
This didn''t work because function pointers needs the object class. With a static method, it''s just like a function so there''s no problem, but... you are limited to use static attributes and methods of the class.
You can do without static methods, but you have to know which the class (or base class) the method comes from.
That is, you should try to replace :
typedef void (APIENTRY * PFNPROGRESSBAR) (float fPercent);
by :
typedef void (APIENTRY CGameManeger::* PFNPROGRESSBAR) (float fPercent);
That will work, but this time you are limited to instances of the CGameManger class only, which may be enough in practice (hopefully)
You can do without static methods, but you have to know which the class (or base class) the method comes from.
That is, you should try to replace :
typedef void (APIENTRY * PFNPROGRESSBAR) (float fPercent);
by :
typedef void (APIENTRY CGameManeger::* PFNPROGRESSBAR) (float fPercent);
That will work, but this time you are limited to instances of the CGameManger class only, which may be enough in practice (hopefully)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement