> Fabien Costantini wrote:
> > ...
> > Also, it really shocks me to see overloaded copy() methods in derived
> > classes of Fl_Image, a fast inspection shows that it only calls the
> > copy(w(),h()) virtual method.
> > So we should also _remove_ all overloaded copy() methods because they
> > duplicate the base class copy behavior.
>
> IIRC we can't do this since a virtual copy() that calls copy(w,h)
> will call the wrong copy(w,h) due to a side-effect of how C++ handles
> such things.
Here's a little demonstrator of what I am explaining:
#include <stdio.h>
class A {
public:
A* copy() { return copy(0,0);}
virtual A* copy(int,int) {printf("Copy from A\n"); return this;}
};
class B: public A {
public:
virtual A* copy(int,int) {printf("Copy from B\n"); return this;}
};
int main(int, char**) {
B b;
A* a = &b;
a->copy();
return 0;
}
Execute it:
[fab]~/Devl $ g++ test.cxx -o test && ./test
Copy from B
So any non virtual method calling a virtual method will call the right derived
class method (here B::copy(int, int)
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev