I need to pass class function as argument for glutIdleFunc. This construction doesn't work:
void (*func)(void) = this->step();
glutIdleFunc(func);
and this too:
void (*func)(void) = Core::step();
glutIdleFunc(func);
How can I do it? Sorry for my stupidity... :)
glutIdleFunc
simply does not support calling a non-static member function. If you want the idle loop to call a method of an object, you will need to place a pointer to the object in a global variable, and have a regular function or static member that calls yourstep
method on that global object.There are two ways you could get this done. The simpler way:
Or, for a slightly greater encapsulation:
In C++, callbacks such as the one accepted by glutIdleFunc() have to be static methods. Try:
Member function of a class have a hidden parameter called this, which is a pointer to their calling object. So when you try to use it a callback, function signatures won't match, you should use static functions which do not have the hidden this parameter.
I think the problem is this line: void (*func)(void) = Core::step();
See you describe the function's signature as void (*func)(void), this is the signature of a C function, not a c++ method. All non-static member methods in c++ are similar to c functions but in addition have a hidden parameter which is a pointer to 'this'.
Try changing the signature to void (Core::*func)(void) = Core::step();
You can call from an instance of the object using: Core test; (test.*test.func)();
"f.test" returns the pointer to the method, and the ".*" operator calls the pointer-to-member function on a class