470,815 Members | 1,097 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

Callbacks and member function pointers

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

Mar 20 '06 #1
2 2050
dj*****@gmail.com wrote:
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
--
jb

(reply address in rot13, unscramble first)
Mar 20 '06 #2
Thank you, I understand now. Cheers!

Mar 21 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by John Silicon | last post: by
3 posts views Thread by n2xssvv g02gfr12930 | last post: by
3 posts views Thread by drsantosh82 | last post: by
3 posts views Thread by Jon Rea | last post: by
18 posts views Thread by tbringley | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.