Callback functions in an fltk class

Hi,

So my problem is that I'm making a class with some fltk objects in but then within this I want callback functions for them to use. I'll write out an illustration:

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>


class fltkstuff{
private:
Fl_Window* window;
Fl_Button* button;
void Button_CallBack(Fl_Widget* , void*);
public:
void set_window();
void set_button();
int run_object();
};
void fltkstuff::set_window(){
window = new Fl_Window(100,100,"Window");
}
void fltkstuff::set_button(){
button = new Fl_Button(20,20,50,50,"Press this");
button -> callback(Button_CallBack);
}

void fltkstuff::Button_CallBack(Fl_Widget* B, void* X){
B->label("Pressed");
}
int fltkstuff::run_object(){
window->end();
window->show();
return Fl::run();
}

int main(){
fltkstuff test;
test.set_window();
test.set_button();
test.run_object();

return 0;
}

But then I get the error that the call back is of <unresolved overloaded function type> and I can't see why.

Any insight would be appreciated (and feel free to comment on any other slips in my code, I'm entirely new to classes and fltk and have only delved into coding on occasion up until now).

Cheers,

Lio.
Last edited on
My guess would be that you forgot the static keyword in the class definition.

1
2
3
4
    // ...
    Fl_Button* button;
    static void Button_CallBack(Fl_Widget* , void*);
    // ... 


And, in the function definition:

1
2
3
void fltkstuff::Button_CallBack(Fl_Widget* B, void* X){
    B->label("Pressed");
}
Last edited on
It was the static void bit I'd missed out, I've just been staring at it for too long. Thanks for the help Cire.
Topic archived. No new replies allowed.