On 2023-03-29 12:21 PM, Charlie R wrote:
> Wed, 29 Mar 2023 12:13:14 +0200, Ralf Fassel:
>
>> * Charlie R <
charl...@wp.pl>
>> | From the derived class, I want to access my base class - the actual |
>> *object* of the base-class part of this.
>>>
>> | One thing that DOES work is to static_cast the (this) pointer into the
>> | base class type, but that seems very sketchy (is this even always |
>> correct?).
>>>
>> | Example - how to fix the 2 "fail" lines?
>> --<snip-snip>--
>> | std::cout << this->base << "\n"; // fails - I want to refer to my
>> parent object
>>
>> std::cout << this->operator int() << "\n";
>> std::cout << operator int()
>
> thanks.
> Though, what when we have 2 base classes and both have int() conversion
> operator?
>
> Is there no direct way of saying "take my base object X" in an expression?
> Is using the static_cast<type_of_base_class*>(this) the valid way?
... or in external code