Suggestion: Change precedence of 'new'
Bill Baxter
dnewsgroup at billbaxter.com
Wed Apr 9 18:32:01 PDT 2008
Sometimes it's handy to invoke a function on a class right after
creating it:
new Thread(&func).run();
Unfortunately that doesn't work in D right now. You have to put
parentheses around the new expression because it has lower precedence
than dotExpression:
(new Thread(&func)).run();
I don't recall how it works in C++, but at least in Java, the first
version works.
I'm not a grammar guru, so can anyone who is say whether the above
change would be possible?
Maybe it would muck up construction based on fully qualified names? So
that
new thread.Thread(&func)
would have to become
new (thread.Thread(&func)
If so that would suck. But Java is able to make it work somehow, and
the construct seems to be used quite heavily there (I've been looking at
a lot of SWT code lately...)
--bb
More information about the Digitalmars-d
mailing list