Jump to content
  • Advertisement
Sign in to follow this  
rogierpennink

Problem with function pointer

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

Hello everyone. I have a bit of a problem with passing function pointers as an argument to a function. That is, the declaration is no problem, but when using the 'passed' function within the function it gives me an error saying: error C2064: term does not evaluate to a function The entire function can be seen below, but before I'll copy 'n paste the code I'll put it in a context as to explain what I'm trying to do. Basically I'm adding functions to a "3d engine" as I continue learning Direct3D. Everytime I've learned something new I think of how I would ease the process and add it to my class. The function below is the InitGameLoop function, which will start the game loop and takes a function pointer as argument. The function the user provides is the 'loop content'.
int u3D::IUniverse3DInterface::U3DInitGameLoop ( bool (*LoopFunc), MSG ** u_msg )
{
	// Initialize windows MSG struct
	MSG msg;	

	// Start the loop
	while ( true ) {

		// Check for windows messages
		if ( PeekMessage ( &msg, NULL, 0, 0, PM_REMOVE ) > 0 )
		{
			// If the user defined the wish to receive the message as well
			if ( u_msg != 0 ) {
				*u_msg = &msg;
			}

			TranslateMessage ( &msg );
			DispatchMessage ( &msg );

		} else {

			// Do the specified game loop
			if ( LoopFunc() == false ) {  // This gives the error
				break;
			}

		}
	}
	
	return msg.wParam;
}

I hope this is enough information, if not, I'll gladly provide more ;-)

Share this post


Link to post
Share on other sites
Advertisement
Ahh, thanks, you are absolutely right and it worked fine :-) In addition - do you always have to add those parentheses when you're dealing with function pointers, or is it just in specific cases like this one?

Share this post


Link to post
Share on other sites
Quote:
Original post by rogierpennink
Ahh, thanks, you are absolutely right and it worked fine :-) In addition - do you always have to add those parentheses when you're dealing with function pointers, or is it just in specific cases like this one?


The parentheses tells the compiler that the type is a function pointer that has a variable number of parameters. Without the parenthesis, you wouldn't be able to specify the parameters types, and the compiler would not be able to ensure type safety.

Regards,

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!