Does D provide automatic dereferencing for accessing members through pointers?

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 27 12:33:24 PDT 2014


On Wed, Aug 27, 2014 at 07:25:41PM +0000, Gary Willoughby via Digitalmars-d-learn wrote:
> This is something that has been on my mind since i discovered this the
> other day. Does D provide automatic dereferencing for accessing
> members through pointers?
[...]

Yes it does.

This is particularly useful in generic code where you neither know (nor
care) if the incoming type was a pointer or not; you can just use the
dot notation and the compiler will do the Right Thing(tm). I remember
trying to write C++ templates that will work for both pointer and
non-pointer types -- it was rather painful due to the distinction
between '.' and '->'. In D you just use '.' throughout and it Just
Works(tm).


T

-- 
One reason that few people are aware there are programs running the
internet is that they never crash in any significant way: the free
software underlying the internet is reliable to the point of
invisibility. -- Glyn Moody, from the article "Giving it all away"


More information about the Digitalmars-d-learn mailing list