C
cps
Hi,
I'm a C programmer taking my first steps into the world of C++.
I'm currently developing a C++ 3D graphics application using GLUT
(OpenGL Utility Toolkit written in C) for the GUI components.
The application is built around a "World" object that contains a "GUI"
object that is a C++ wrapper around GLUT. What I'd like to do is pass a
pointer to a member function in the World class to function in the GUI
class.
Here are the functions I'd like to pass:
void World:isplay()
{
/* clear all pixels */
glClear(GL_COLOR_BUFFER_BIT);
Do OpenGL stuff...
}
void World::Keyboard(unsigned char key, int x, int y)
{
cout << key << endl;
Handle keyboard...
}
I'd like to pass these functions to the constructor of the GUI object
as follows:
p_GUI = new GUI(Display, Keyboard);
I'm getting the following error:
World.cpp(16) : error C2664: 'GUI::GUI(void (__cdecl *)(void),void
(__cdecl *)(unsigned char,int,int))' : cannot convert parameter 1 from
'void (void)' to 'void (__cdecl *)(void)'
None of the functions with this name in scope match the target
type
I understand that (__cdecl *) is a calling convention. What I can't
figure out is how to fix the syntax so that the code compiles.
Any help with this (especially a simple example) would be very much
appreciated.
Cheers,
Chris
I'm a C programmer taking my first steps into the world of C++.
I'm currently developing a C++ 3D graphics application using GLUT
(OpenGL Utility Toolkit written in C) for the GUI components.
The application is built around a "World" object that contains a "GUI"
object that is a C++ wrapper around GLUT. What I'd like to do is pass a
pointer to a member function in the World class to function in the GUI
class.
Here are the functions I'd like to pass:
void World:isplay()
{
/* clear all pixels */
glClear(GL_COLOR_BUFFER_BIT);
Do OpenGL stuff...
}
void World::Keyboard(unsigned char key, int x, int y)
{
cout << key << endl;
Handle keyboard...
}
I'd like to pass these functions to the constructor of the GUI object
as follows:
p_GUI = new GUI(Display, Keyboard);
I'm getting the following error:
World.cpp(16) : error C2664: 'GUI::GUI(void (__cdecl *)(void),void
(__cdecl *)(unsigned char,int,int))' : cannot convert parameter 1 from
'void (void)' to 'void (__cdecl *)(void)'
None of the functions with this name in scope match the target
type
I understand that (__cdecl *) is a calling convention. What I can't
figure out is how to fix the syntax so that the code compiles.
Any help with this (especially a simple example) would be very much
appreciated.
Cheers,
Chris