Why can't we make reference variables?
Nick Sabalausky
SeeWebsiteToContactMe at semitwist.com
Tue Aug 28 23:04:44 PDT 2012
On Tue, 28 Aug 2012 22:08:11 -0700
Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> On Wednesday, August 29, 2012 06:46:25 Tommi wrote:
> > The weird thing is that you can use a member access operator with
> > a pointer (without explicitly dereferencing the pointer first).
>
> Well, you clearly haven't done much pointers to structs in D,
I indeed haven't :) Usually "ref MyStruct" is good enough for my needs.
> or that
> wouldn't be surprising at all. . always implicitly dereferences the
> pointer, which pretty much makes the -> operator completely
> unnecessary.
>
I always figured it was just the reference semantics for classes (and
the optional "ref" when passing structs) that eliminated the need
for ->.
Probably 99+% of the time I use structs it's either a
plain-old-struct or "ref MyStruct", so I assumed C-style "(*foo).bar"
was good enough for the rare uses of "MyStruct*", and it never
bothered me.
But it's definitely pretty cool that dot still works even for pointers.
It's awesome that D is still pleasantly surprising me :)
Out of curiosity, what about "MyStruct**" or "MyClass*"?
More information about the Digitalmars-d
mailing list