Skip to main content
gamedev.net
🔒 Locked

error c2664 (callback within class method)

Started by mudlouse Jan 19, 2007 at 7:53 PM 2 replies 1.1k views
Original Post
mudlouse
mudlouse
Hi, I'm trying to create a menu with glut (although probably not glut specific) and Cpp but it's giving me an error at compile. I'm not completely certain but I think it has something to do with a callback within a class. Basically the code is supposed to bring up a menu, which changes some variables depending on which option you select. In my menu.cpp

void Menu::createMenu(void) {

	menu = glutCreateMenu(processEvents);		//error c2664

		glutAddMenuEntry("Red", 0);
		glutAddMenuEntry("Green", 1);
		glutAddMenuEntry("Blue", 2);

	glutAttachMenu(GLUT_RIGHT_BUTTON);
}

void Menu::processEvents(int event) {

	switch(event) {

		case 0:	bgRed = 1;
				bgGreen = 0;
				bgBlue = 0;
				break;

		case 1:	bgRed = 0;
				bgGreen = 1;
				bgBlue = 0;
				break;

		case 2:	bgRed = 0;
				bgGreen = 0;
				bgBlue = 1;
				break;		
		default:	break;
	}
}

the error:

error C2664: 'glutCreateMenu' : cannot convert parameter 1 from 'void (int)' to 'void (__cdecl *)(int)'
        None of the functions with this name in scope match the target type

Can someone help? Thanks.
JohnBolton
JohnBolton
Quote:
Original post by Anonymous Poster
A none static member function requires a pointer to the class to be able to call the function. The signatures of the required function in glut and the class member function are therefore different and none compatible.


In other words, the function must be either a non-member function or a static member function.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
mudlouse
mudlouse
thanks for that, i guess it's time for some reading up on static functions :)

Topic Locked

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

Sign in to reply to this topic.