This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Covariant returns?
> 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.
So even though C::This is called, the return value must be converted
to B*, when calling the virtual function for a B*.
Martin