Callbacks and member function pointers

D

djcredo

Hello,

I'm using C++ with OpenGL and GLUT. But I'm having problems with
callbacks.

There is a function called "glutDisplayFunc" which receives function
pointers as input, specifically "void (*func)(void)".

I'm calling the function inside the constructor of a class called
GLTestOne, and the input I am giving is to the function "void
GLTestOne::DrawGLScene()".

When I call the function, I use:

glutDisplayFunc(DrawGLScene)

.... however, the compiler complains that the pointer is of type "void
(GLTestOne::)(void)" instead of the required "void (*)(void".

How can I do this correctly? I'm still quite hazy with member function
pointers.

Cheers
 
J

Jakob Bieling

Hello,

I'm using C++ with OpenGL and GLUT. But I'm having problems with
callbacks.

There is a function called "glutDisplayFunc" which receives function
pointers as input, specifically "void (*func)(void)".

I'm calling the function inside the constructor of a class called
GLTestOne, and the input I am giving is to the function "void
GLTestOne::DrawGLScene()".

When I call the function, I use:

glutDisplayFunc(DrawGLScene)

... however, the compiler complains that the pointer is of type "void
(GLTestOne::)(void)" instead of the required "void (*)(void".

How can I do this correctly? I'm still quite hazy with member function
pointers.

You *have to* pass a function, that does not need a this pointer.
There is no way around it. To be still able to use it, you commonly pass
a *static* member function which can then either do work or pass the
call on to the appropriate object.

hth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top