> the Fltk libray is very new for me...and i have some trouble using
> callbacks, i really don't get it.
>
> if we assume that i have a class like that :
>
> class C{
> int property;
> void setProp(int value){property = value;};
> }
>
> I just want from a fl_menu call the function setProp.
> How can i manage to do that ?
This is covered in the FLTK-1.1.x documentation, available online at:
http://www.fltk.org/documentation.php/doc-1.1/common.html#common
Many programmers new to FLTK or C++ try to use a non-static class
method instead of a static class method or function for their
callback. Since callbacks are done outside a C++ class, the this
pointer is not initialized for class methods.
To work around this problem, define a static method in your class
that accepts a pointer to the class, and then have the static
method call the class method(s) as needed. The data pointer you
provide to the callback() method of the widget can be a pointer
to the instance of your class.
class Foo {
void my_callback(Fl_Widget *w);
static void my_static_callback(Fl_Widget *w, void *f) {
((Foo *)f)->my_callback(w);
}
...
}
...
w->callback(my_static_callback, (void *)this);
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev