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
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to