472,949 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,949 software developers and data experts.

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 2139
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John Silicon | last post by:
Has anyone ever successfully implimented passing member-functions to a varargs function? I thought it would be fairly straight-forward, but seems to come up with nice syntax errors. I've checked...
13
by: Andy | last post by:
Hi, Sorry for the naive question. What I did here is to check the value of pointers to member functions, and try to call these member function via member functio pointers. But the program...
4
by: Aaron Walker | last post by:
Greetings, I'm attempting to write my first *real* template function that also deals with a map of strings to member function pointers that is making the syntax a little tricky to get right. ...
3
by: n2xssvv g02gfr12930 | last post by:
Does anybody know of a smart pointer that supports 'operator->*'. As yet I've always had to use this type of expression ((*sp).*pFnc)() where sp .... Smart pointer to Obj pFnc .. Member...
3
by: Dilip | last post by:
I am stuck with a syntactical issue and would appreciate some help: I have a class with a templated mem fn like so: class A { }; template<typename Ret, typename P1, Ret (A::*fp)(P1*)>...
3
by: drsantosh82 | last post by:
Hi, I am trying to implement a callback routine using function pointers. Basically, I am trying to avoid tying my callback invoking member to a particular class. Let me explain my problem...
3
by: Jon Rea | last post by:
Hello all, Sorry if this is long, but I wanted to be specific... Can anyone shed any light on the following errors in the context of the following example code: cullMethod1(); // compiles,...
18
by: tbringley | last post by:
I am a c++ newbie, so please excuse the ignorance of this question. I am interested in a way of having a class call a general member function of another class. Specifically, I am trying to...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.