• Advertisement

Archived

This topic is now archived and is closed to further replies.

Functon pointers

This topic is 5511 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I use function pointers in my CScript class, however they seem to not be working. I belive the problem lies in my typedef:
typedef int (*pFunc)(CGame*);
 
This is supposed to be a typedef for a func-pointer take a CGame pointer as an argument and returning an integer. Later on in my code I call it like this:
  
void CCommand::Execute(CGame *pGame)
{
	int Result;
	Result = pFunc(pGame);
}
  
pFunc is a private member of CCommand. But I get an error message telling me that
C:\...\CCommand.cpp(46) : error C2440: ''='' : cannot convert from ''int (__cdecl *)(class CGame *)'' to ''int'' 
Why wouldnt this work? is it my typedef, or could it be something else?

Share this post


Link to post
Share on other sites
Advertisement
pFunc is a type, not an actual pointer.

You need to do:

int egerg(CGame*);

pFunc x = egerg;
x(pGame);

Share this post


Link to post
Share on other sites

  • Advertisement