glutTimerFunc and error C3867: non-standard syntax; use '&' to create a pointer to me

So I’m trying to use glutTimerFunc inside a class that I’ve made.

Particularly I have function


void ColorInterpolator::interpolateColor(int t) {
    ...
}

void ColorInterpolator::changeColor() {
    ...
    ...
    glutTimerFunc(50, this->interpolateColor, step/maxsteps);
}

the line with glutTimerFunc gives error:

error C3867: 'ColorInterpolator::interpolateColor': non-standard syntax; use '&' to create a pointer to member

How should I reference interpolateColor()?

Do you have more than one instance of ColorInterpolator?

If you only have one instance, then you can just store the pointer in a global variable and wrap interpolateColor() in a plain function (which, technically, needs to be declared with [var]extern “C” …[/var]).

If you have more than one instance, then you have a problem, because you need to pass both the instance pointer (“this”) and the interpolation fraction (step/maxsteps), but the glutTimerFunc() interface only allows a single integer to be passed to the callback.

One option is to store the parameters in an array or vector so that you can pass an index to glutTimerFunc().

[QUOTE=mavavilj;1292248]So I’m trying to use glutTimerFunc inside a class that I’ve made.

Particularly I have function


void ColorInterpolator::interpolateColor(int t) {
    ...
}

void ColorInterpolator::changeColor() {
    ...
    ...
    glutTimerFunc(50, this->interpolateColor, step/maxsteps);
}

the line with glutTimerFunc gives error:

error C3867: 'ColorInterpolator::interpolateColor': non-standard syntax; use '&' to create a pointer to member

How should I reference interpolateColor()?[/QUOTE]

As I stated in another (yours?) thread, just use a lambda. This should do the trick:


void ColorInterpolator::interpolateColor(int t) {
    ...
}

void ColorInterpolator::changeColor() {
    ...
    ...
    glutTimerFunc(50, [this](int t){interpolateColor(t);}, step/maxsteps);
}

Might not compile because of coding errors I made, but generally this should work.