Covariant returns?

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Tue Mar 7 11:28:00 GMT 2000


> > So even though C::This is called, the return value must be converted
> > to B*, when calling the virtual function for a B*.
> 
> The type returned is a pointer.  Specifically the this pointer for C.
> Now I'm not too familiar with the internals of the compiler nor the
> implementation specifics of c++ in gcc.  But I still don't see why the
> value of C::this would be different no matter what the return type
> for the method is.

Because of the pointer adjustments in multiple inheritance. Please
review

http://gcc.gnu.org/ml/gcc/2000-03/msg00144.html

As you can see, &c is effff9b0, whereas (B*)&c is effff9b4.  So it is
clear that you interpreting effff9b0 as a B* is an error in the
compiler.

> You agree that in the calls to a->This(), b->This()   C::This() is
> invoked which returns C::this which will have the same value in all
> three calls.  No?

They should *not* have the same values. b->This() should be (B*)&c,
not &c.

Regards,
Martin


More information about the Gcc mailing list