Inconsistency with function pointers
anonymous
anonymous at example.com
Sat Aug 4 09:42:37 PDT 2012
On Saturday, 4 August 2012 at 15:23:39 UTC, Russel Winder wrote:
[...]
> I can do:
[...]
> auto f() { return delegate () { writeln("Hello
> World."); }; }
> auto t = new Thread(f);
[...]
> However:
[...]
> auto t = new Thread( delegate () { return delegate ()
> { writeln("Hello World."); }; } ) ;
[doesn't work]
You need parentheses to call the anonymous delegate:
auto t = new Thread( delegate () { return delegate () {
writeln("Hello World."); }; }()) ;
You don't need them with f, because there you have to write &f to
refer to the delegate itself. (And because you don't use
-property.)
More information about the Digitalmars-d-learn
mailing list