GLFW Callback Trouble

Started by
1 comment, last by davexunit 15 years, 9 months ago
I have a class that includes all my GLFW callback functions, but I get an error when I try to set the callbacks. The error is: "argument of type `void (dave::gui::Root::)(int, int)' does not match `void*'" It seems that GLFW callbacks must be in the global namespace. Is there any way around this so that I don't have to have these callbacks in the global namespace? The first solution I came up with was to have the callbacks in the global namespace, and then making the original callbacks in my class public, and then calling those from the global callback functions. This is very messy to me and I'd like to avoid this "solution" if possible. Any ideas are appreciated. Thanks.
Advertisement
They do not need to be in the global namespace, the compiler just needs to know their location on compile time. That means they will have to be static functions within the class, usually callbacks over a void* to pass the class in, like this.

class MyClass{public:    static void myCallback(void*);private:    void myCallback();};void MyClass::myCallback(void* data){    MyClass* my_class = reinterpret_cast<MyClas*>(data);    my_class->myCallback();}I do not really know what GLFW offers though.
Ohhhh... okay I get it.
Thanks for the help and the quick response!

This topic is closed to new replies.

Advertisement