> 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
Ok, I think what Mike may mean here is not about the method calls which will be
correctly resolved but of method name masking
So in my example if you add in main:
b.copy();
it won't be resolved (at least on gcc) because gcc would find only copy(),
you'll need at a minimum to call b.A::copy();
Fabien
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev