Jump to content
  • Advertisement
Sign in to follow this  
MTclip

member function pointer - - set up ?

This topic is 4870 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
Advertisement
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
myGame is a pointer so you use ->* to bind the function pointer.

int result = (myGame->*funcPtr)(&command);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!