On 22.07.2010, at 15:47, Zoltán Lengyel wrote: > Hi, > I have an access violation problem in my project, I made a small example for > demonstration: > http://paste-bin.com/view/38d8960c > > So there's class A, subclassed from Fl_Group, it has a button, thats > callback is using a virtual function, wich is implemented in class B > (subclassed from class A). The program compiles fine, but when you use the > button, it drops an Access Violation (same happens if I use Fl_Scroll > instead of Fl_Group, if I subclass A from a container I get this error I > guess). > > In this second case, I changed the base of the A class, so it is now > subclassed from Fl_Button, and with the same callback everything wokrs fine, > the program exits after button press. > http://paste-bin.com/view/8d417487 > > This may be not an FLTK problem at all, my knowledge of classes have leaks, > but I am really starving for help here! > Thanks.
I think it's a miss-interpretation of FLTK's callback mechanism. From <http://paste-bin.com/view/38d8960c>: static void cb(Fl_Widget *v, void *o) { ( (A*)v )->cb_i(); } In this static callback method, the first argument (Fl_Widget *v) is the originating widget of the callback, i.e. Fl_Button*. Casting this to your class A* is definitely wrong. OTOH, argument #2 is the "this" pointer of your class A, as set up in the initialization (i.e. "A* o"). Thus, the correct method cb should read: static void cb(Fl_Widget *v, void *o) { ( (A*)o )->cb_i(); } I didn't test this, but this ought to work with your virtual method. The fact that it "worked" in your 2nd example appears just to be good luck or something like this... ;-) Albrecht _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk

