Suggestion: Change precedence of 'new'

Lionello Lunesu lionello at lunesu.remove.com
Wed Apr 9 22:01:35 PDT 2008


"Bill Baxter" <dnewsgroup at billbaxter.com> wrote in message 
news:ftjqml$2oo4$1 at digitalmars.com...
> 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.

In C# the first one works, too.

In D, "new" already has higher precedence than "cast", which is more useful, 
IMHO:

#Foo foo = cast(Foo)new Bar;

L. 




More information about the Digitalmars-d mailing list