C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Contradiction about this parameter in the C++ standard

From: language.lawyer_at <language.lawyer_at_[hidden]>
Date: Tue, 19 Apr 2022 14:27:30 +0300
On 19/04/2022 14:16, Jens Maurer wrote:
> On 19/04/2022 11.57, Edward Catmur via Std-Proposals wrote:
>> On Tue, 19 Apr 2022 at 09:46, <language.lawyer_at_[hidden] <mailto:language.lawyer_at_[hidden]>> wrote:
>>
>> On 19/04/2022 11:24, Edward Catmur wrote:
>
>> > Yes, I think that's where the connection is made. So that's possibly a
>> > derived class object, and it's worth explaining where the this pointer with
>> > type pointer to base gets its value from.
>>
>> IDK, why/when having «the object for which function is invoked» meaning «the result of the object expression» and overloading the definition of `this` with «or to its base class subobject» is useful?
>>
>>
>> What else could "the object for which function the is invoked" mean other than "the result of the object expression"?
>
> Consider this example:
>
> x.f();
>
> If f is a member function of a base class, you need to convert
> "x" to the base class type. In most implementations, if the base
> class is not the first one in your base-specifier, this means
> adjusting the address that "x" represents by the offset of the
> base subobject inside the "x".
>
> This is what the standard wants to capture, and that's why
> the value of "this" is not just the value of the object
> expression.

`this` will point to the corresponding subobject, Edward's proposal is to always mean "the result of the object expression" by "the object for which function the is invoked", but change `this` definition to say that it is not always points at "the object for which function the is invoked".

Received on 2022-04-19 11:27:33