Sign in to follow this  
danielgomez22

glutTimerFunc and objects

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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!!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this