-> and :: operators

Idan Arye via Digitalmars-d digitalmars-d at puremagic.com
Sun Oct 11 02:43:02 PDT 2015


On Friday, 9 October 2015 at 19:48:39 UTC, Dmitry Olshansky wrote:
> On 09-Oct-2015 21:44, Freddy wrote:
>> On Friday, 9 October 2015 at 04:15:42 UTC, Ali Çehreli wrote:
>>> Semi-relatedly, a colleague who has heard many D sales 
>>> pitches from me
>>> over the years is recently "looking at Go" and liking it very 
>>> much. He
>>> came to me today telling me about this awesome 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. :) )
>>>
>>> Ali
>>
>> Stole from D? You mean java right?
>
> There is no value type objects in Java so no. More likely C#.

Nope - C# uses -> to access member of a struct referenced by a 
pointer. See 
https://msdn.microsoft.com/en-us/library/50sbeks5.aspx

The difference between reference types and pointers is that with 
reference types, THERE ARE NO value varaiables. So it's safe to 
use . instead of -> for accessing member through a reference 
because there is no value type, because there is no such a thing 
as accessing a member of a reference type without dereferencing 
it. So it's safe to do so on classes in C#, but not on structs.

This is the innovation in D(regarding this issue) - that on 
struct types, the same operator is used for BOTH the value type 
and the pointer to it.


More information about the Digitalmars-d mailing list