plz help! Calling another program, compile errors all the same

Started by
4 comments, last by gargoyle 14 years, 6 months ago
My team mate wrote code based on a lesson videotutorialsrock.com so it has all the usual methods:

int main()
initRendering()
drawScene()
update(int value)
etc, Now i've written the main code of this program separatetly and now I'm just trying to put the two together. In order to do that i changed his program into a new class which i called Creator and changed the "main" method in his class like this

int Creator::mazemain() {
		//glutInit(&argc, argv);
		glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
		glutInitWindowSize(windowSizeX, windowSizeY);                   // Set Window size according to global variables windowSizeX, windowSizeY

		glutCreateWindow("Maze");                                       // Create game window, called "Maze"
		initRendering();

		//Set handler functions
		glutDisplayFunc(drawScene);                                     // draws display to screen
		glutWarpPointer((windowSizeX/2), (windowSizeY/2));				// warps pointer X, Y location relative to bottom left of screen (in this case middle of screen)
		glutPassiveMotionFunc(processMouseMotion);                      // allows program to process passive mouse motion, handled with processMouseMotion
		glutMouseFunc(processMouseClick); 
		glutKeyboardFunc(handleKeypress);								// enables program to process game effects in response to button presses
		glutSpecialFunc(processSpecialKeys);							// enables use of special keys such as directional and F locked keys for game functionality
		glutIdleFunc(drawScene);                                        // used for pausing game while menu is being used
		glutReshapeFunc(handleResize);                                  // handles resizing of game window                                           // allows the program to utilise menu functionality
		
		glutMainLoop();
	return 0;
}

My program is the core of the game, his code simply provides a graphical way of making changes which are saved to a file in which my code opens and reads. So what i want my program to do is to call Creator::mazemain() and wait until the user has exited the program (after they've done their changes in the gui and saved to a file). So i made a Creator class in my program and called his Creator::mazemain fucntion. When i compile i get the following errors: 'Creator::update': function call missing argument list; use '&Creator::update' to create a pointer to member 'Creator::drawScene': function call missing argument list; use '&Creator::drawScene' to create a pointer to member 'Creator::processMouseMotion': function call missing argument list; use '&Creator::processMouseMotion' to create a pointer to member 'Creator::processMouseClick': function call missing argument list; use '&Creator::processMouseClick' to create a pointer to member 'Creator::processMouseClick': function call missing argument list; use '&Creator::processMouseClick' to create a pointer to member 'Creator::processSpecialKeys': function call missing argument list; use '&Creator::processSpecialKeys' to create a pointer to member 'Creator::drawScene': function call missing argument list; use '&Creator::drawScene' to create a pointer to member 'Creator::handleResize': function call missing argument list; use '&Creator::handleResize' to create a pointer to member I made the changes it suggested for the very first error and changed

glutTimerFunc(10, update, 0); 
to


glutTimerFunc(10, &Creator::update, 0);      
And this is the new error I got after re-compiling. error C2664: 'glutTimerFunc' : cannot convert parameter 2 from 'void (__thiscall Creator::* )(int)' to 'void (__cdecl *)(int)' All my 8 errors are the same so if i fix one then i'll know how to fix the rest, Could someone please tell me how to fix this problem, cos yeh all i want to do is call his program, have the user make the changes in that program, and when the user exits that program my program can continue execution. I really appreciate the help :) Thanx :)
Advertisement
Well the error message tells you exactly what you need to do to fix it. You need to use &functionName rather than functionName when passing it to GLUT.

glutDisplayFunc(&drawScene);
glutPassiveMotionFunc(&processMouseMotion);
glutMouseFunc(&processMouseClick); glutKeyboardFunc(&handleKeypress); glutSpecialFunc(&processSpecialKeys); glutIdleFunc(&drawScene);
glutReshapeFunc(&handleResize);

The reason for this is that GLUT is expecting pointers to the functions so that it can call them back when required.
Looks to me that the problem is that you're passing a member function pointer to GLUT instead of a "regular" fucntion pointer.

Use a static member function, or use a non-member wrapper function.
Hey i changed my code as you suggested to the following and I'm still getting
errors.

int Creator::mazemain() {		//glutInit(&argc, argv);		glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);		glutInitWindowSize(windowSizeX, windowSizeY);                   // Set Window size according to global variables windowSizeX, windowSizeY		glutCreateWindow("Maze");                                       // Create game window, called "Maze"		initRendering();		//Set handler functions		glutDisplayFunc(&drawScene);                                     // draws display to screen		glutWarpPointer((windowSizeX/2), (windowSizeY/2));				// warps pointer X, Y location relative to bottom left of screen (in this case middle of screen)		glutPassiveMotionFunc(&processMouseMotion);                      // allows program to process passive mouse motion, handled with processMouseMotion		glutMouseFunc(&processMouseClick); 		glutKeyboardFunc(&handleKeypress);								// enables program to process game effects in response to button presses		glutSpecialFunc(&processSpecialKeys);							// enables use of special keys such as directional and F locked keys for game functionality		glutIdleFunc(&drawScene);                                        // used for pausing game while menu is being used		glutReshapeFunc(&handleResize);                                  // handles resizing of game window                                           // allows the program to utilise menu functionality				glutMainLoop();	return 0;}


and i got the following error messages:


error C2276: '&' : illegal operation on bound member function expression
error C2276: '&' : illegal operation on bound member function expression
error C2276: '&' : illegal operation on bound member function expression
error C2276: '&' : illegal operation on bound member function expression
etc

This error was on each of those lines i just changed and put the &function name.


I tried a similar version as follows:

int Creator::mazemain() {		//glutInit(&argc, argv);		glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);		glutInitWindowSize(windowSizeX, windowSizeY);                   // Set Window size according to global variables windowSizeX, windowSizeY		glutCreateWindow("Maze");                                       // Create game window, called "Maze"		initRendering();		//Set handler functions		glutDisplayFunc(&Creator::drawScene);                                     // draws display to screen		glutWarpPointer((windowSizeX/2), (windowSizeY/2));				// warps pointer X, Y location relative to bottom left of screen (in this case middle of screen)		glutPassiveMotionFunc(&Creator::processMouseMotion);                      // allows program to process passive mouse motion, handled with processMouseMotion		glutMouseFunc(&Creator::processMouseClick); 		glutKeyboardFunc(&Creator::handleKeypress);								// enables program to process game effects in response to button presses		glutSpecialFunc(&Creator::processSpecialKeys);							// enables use of special keys such as directional and F locked keys for game functionality		glutIdleFunc(&Creator::drawScene);                                        // used for pausing game while menu is being used		glutReshapeFunc(&Creator::handleResize);                                  // handles resizing of game window                                           // allows the program to utilise menu functionality				glutMainLoop();	return 0;}



and i got these errors.

error C2664: 'glutTimerFunc' : cannot convert parameter 2 from 'void (__thiscall Creator::* )(int)' to 'void (__cdecl *)(int)'

error C2664: 'glutDisplayFunc' : cannot convert parameter 1 from 'void (__thiscall Creator::* )(void)' to 'void (__cdecl *)(void)'

error C2664: 'glutPassiveMotionFunc' : cannot convert parameter 1 from 'void (__thiscall Creator::* )(int,int)' to 'void (__cdecl *)(int,int)'

error C2664: 'glutMouseFunc' : cannot convert parameter 1 from 'void (__thiscall Creator::* )(int,int,int,int)' to 'void (__cdecl *)(int,int,int,int)'

error C2664: 'glutKeyboardFunc' : cannot convert parameter 1 from 'void (__thiscall Creator::* )(unsigned char,int,int)' to 'void (__cdecl *)(unsigned char,int,int)'

error C2664: 'glutSpecialFunc' : cannot convert parameter 1 from 'void (__thiscall Creator::* )(int,int,int)' to 'void (__cdecl *)(int,int,int)'

: error C2664: 'glutIdleFunc' : cannot convert parameter 1 from 'void (__thiscall Creator::* )(void)' to 'void (__cdecl *)(void)'


error C2664: 'glutReshapeFunc' : cannot convert parameter 1 from 'void (__thiscall Creator::* )(int,int)' to 'void (__cdecl *)(int,int)'


Any ideas ?? Sorry i don't understand what you are telling me to do BertS, i've only started c++/openGl this semeser. :(

Thanx
Keep the calls as I showed you, but change the Class declaration so that the functions are static:

class SomeClass
{
Public:
static void DrawScene();
static void SomeOtherFunction();
}
Thanx a heap AndyEsser, you're a life saver! :D

Cheers

This topic is closed to new replies.

Advertisement