-> and :: operators

Atila Neves via Digitalmars-d digitalmars-d at puremagic.com
Fri Oct 9 07:26:49 PDT 2015


On Friday, 9 October 2015 at 12:19:55 UTC, Ola Fosheim Grøstad 
wrote:
> On Friday, 9 October 2015 at 04:15:42 UTC, Ali Çehreli wrote:
>> Go feature where you just type a dot after a pointer and the 
>> language is so great that it works! You don't need to type 
>> (*p).member. Isn't Go awesome!
>>
>> I responded "yep, it's a great feature and those gostards will 
>> never admit that they took that feature from D." (There is 
>> probably earlier precedence but it felt great to say it to my 
>> friend. :) )
>
> Just about all higher languages does this, since the reference 
> type does not have members. Simula too.
>
> But this unfortunately breaks down when you add smart-pointers, 
> which makes this approach unsound since pointer-type members 
> collide with object members.
>
> So C++ actually got this right by requiring explicit 
> dereferencing.

The only case in which the C++ way is right is when there are two 
member functions of the same name in the pointed-to object and 
the smart pointer itself since you can disambiguate `ptr->get()` 
from `ptr.get()`.

Atila


More information about the Digitalmars-d mailing list