The daily D riddle

H. S. Teoh hsteoh at quickfur.ath.cx
Sun Jan 28 07:40:16 UTC 2018


On Sun, Jan 28, 2018 at 12:04:42AM -0700, Jonathan M Davis via Digitalmars-d wrote:
> On Saturday, January 27, 2018 23:44:40 Jonathan M Davis via Digitalmars-d 
> wrote:
[...]
> > It does exactly what I'd expect it to do, though honestly, it's the
> > sort of thing I wish weren't legal, just like I wish that it weren't
> > legal to call a static member function via a member. Maybe there are
> > cases where it's useful, but it just seems wrong.
> 
> via in instance, I mean. IMHO, it should be required to do
> Type.staticMember rather than var.staticMember. The fact that it's
> allowed is just messy and is one of the things that we inherited from
> C++ that we shouldn't have. This case falls in the same camp, except
> that it's a new mistake, since C++ doesn't have init values.
[...]

Are you sure this came from C++? I'm pretty sure instance.staticMember
(or instance->staticMember) is not allowed in C++, you have to write
Class::staticMember. I distinctly remember, having gotten used to the
distinction in C++, being a little surprised that D was lax in this
area. In fact, I remember running into problems with my early D code
where I relied on this distinction, only to quickly find myself drowning
in overload conflicts / ambiguity errors when I tried invoking the
methods.


T

-- 
Making non-nullable pointers is just plugging one hole in a cheese grater. -- Walter Bright


More information about the Digitalmars-d mailing list