> Fabien Costantini wrote:
>
> [ Mike Sweet wrote ]
> >> 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)
>
> Okay, that works. But what is the side effect, if A::copy() is
> virtual? I get the same result. Wrong example?
>
> Albrecht
In fact, it will also work because any message sent to an object is resolved
into a call deducted dyna,ically from its virtual method table (VMT) which
contains a ref to itself and the correct pointers to methods (this in c++, self
in java).
Anyway, what matters here is that it _will_ work perfectly the way described it
(so even if copy() is not virtual).
Fabien
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev