glutTimerFunc and objects

Started by
2 comments, last by AndyEsser 14 years, 8 months ago
Hi The thing is that I have an object Sphere (a c++ object) with a method call checkState that look like: void Sphere::checkState(int value){ if(_state == 'j'){ jump(); } glutTimerFunc(DELTA_FALL_TIME, checkState, 0); //Here is the problem } and it says error: argument of type ‘void (Sphere::)(int)’ does not match ‘void (*)(int)’ it says that glitTimerFunc only acepts static functions???' or how can I say it to call the funcion of my object I will apreciate rapid responces Thanks!! Daniel
Advertisement
In your class declaration you will want to declare the function as:

void static checkState(int value);

And in the call to glutTimerFunc() you will probably want to pass the Class pointer (this) in order to be able to access that class. I'm assuming that's what the parameter currently set to 0 is for.


Hi

Thanks for the rapid responce

The idea is:

I change the declaration of the method to this:

static void checkState(Sphere *s);

and the method to:


static void Sphere::checkState(Sphere* s){
if(s->getState() == 'j'){
s->jump();
}
glutTimerFunc(DELTA_FALL_TIME, checkState, 0);
}


right?

but it says to me: cannot declare member function ‘static void Sphere::checkState(Sphere*)’ to have static linkage

and how I say yo gluTimerFunc that the paramether of the checkState is this??

thanks!!
Change the declaration to

static void checkState(Sphere *s);

You don't need to change the method. You can keep that as it is.

Having just read the specification about glutTimerFunc it would appear that the final parameter is not what I thought it was.

Changing the declaration as I said above should fix your problem.

This topic is closed to new replies.

Advertisement