Covariant returns?

sidster patrick@mail.boxsoft.com
Tue Mar 7 01:55:00 GMT 2000


* Martin v. Loewis (martin@loewis.home.cs.tu-berlin.de) [20000307 01:21]:
> > The This() methods were specified to be virtual.  Meaning if you have a
> > pointer of a base type to the dereived object and you invoke any virtual
> > methods that are defined in the derived class the actual method invoked
> > will be the one for the derived class.
> > 
> > That is why invoking    a->This(), b->This(), c->This()
> > will all invoke         C::This()
> 
> Sure, I understand that part. However, 5.2.2, [expr.call]/4 says
> 
> # The value of a function call is the value returned by the called
> # function except in a virtual function call if the return type of the
> # final overrider is different from the return type of the statically
> # chosen function, the value returned from the final overrider is
> # converted to the return type of the statically chosen function.


Sure,  I have no problem with this statement.


> 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.

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?

There doesn't seem to be (at least it is not obvious to me that there
is) any type conversion.  Maybe I'm missing something ... in which case
I appologise for my ignorance.


patrick
--
It's a damn poor mind that can only think of one way to spell a word.
      -- Andrew Jackson


More information about the Gcc mailing list