Sign in to follow this  

member function pointer - - set up ?

This topic is 4532 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

okay ive been working on setting this up for a couple days now.. ive ran into a slight or maybe not so slight problem.. this snippet should be enought to get my question across
////////////////////////////////////
/// Commands.h ////
class CCommands
{
	/*STUFF*/
}
// JUST TO MAKE THINGS CLEAR

//////////////////////////////////////////
/// Console.h /////
#include "Commands.h"
class myGame  // for external reference
//
class CConsole
{
	CCommands * myCommnads;
	 // member function pointer
	int (myGame::*funcPtr)(CCommands*);
//
	void init()
	{
		//OTHER STUFF
		
		funcPtr = &myGame::consoleParser;
		return;
	}
//
	int CConsole::OnKeyDown(WPARAM wParam)
	{
		//calls the pointed function
		// not sure if this is how to call it ..
		int result = funcPtr;				
		return 0;		
	}
}

///////////////////////////////
/// main.cpp ///

#include "Console.h"
#include "Commands.h"
class myGame
{
	CConsole *myConsole
	
	int consoleParser( CCommands* pCommand )
	{
		/*stuff*/
	}
}
winMain()
{
	myGame* thisGame
	//Stuff
}

I get these errors when i compile my code Console.cpp(88): error C2027: use of undefined type 'myGame' Console.cpp(88): error C2276: '&' : illegal operation on bound member function expression looks as if i have missunderstood how to do this How should i set this up any help would be much thanked..

Share this post


Link to post
Share on other sites
Well thanks for that I got it to compile ;P

how would i dereference the pointer to call the function

int result = *funcPtr(&command);
int result = (myGame.*funcPtr)(&command);
int result = (*funcPtr)(&command);

does not work

mainly get this error
Console.cpp(305): error C2064: term does not evaluate to a function taking 1 arguments

that does not make sense its declared like this
int (myGame::*funcPtr)(CCommands*);

Share this post


Link to post
Share on other sites

This topic is 4532 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this