Skip to main content
gamedev.net
🔒 Locked

Functon pointers

Started by Laroche 1 reply 200+ views
Original Post
Laroche
Laroche
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?
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
civguy
civguy
pFunc is a type, not an actual pointer.

You need to do:

int egerg(CGame*);

pFunc x = egerg;
x(pGame);
Laroche
Laroche
ah, true. Thanks for the help!
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.