Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

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

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2018
    Posts
    10

    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

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

    the line with glutTimerFunc gives error:

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

    How should I reference interpolateColor()?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,984
    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 extern "C" ...).

    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().

  3. #3
    Intern Contributor
    Join Date
    Oct 2014
    Posts
    74
    Quote Originally Posted by mavavilj View Post
    So I'm trying to use glutTimerFunc inside a class that I've made.

    Particularly I have function

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

    the line with glutTimerFunc gives error:

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

    How should I reference interpolateColor()?
    As I stated in another (yours?) thread, just use a lambda. This should do the trick:
    Code :
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •