Problem with trying sample from doc page

Pavel via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jul 16 08:12:57 PDT 2014


Hi! I've been experimenting with D functions, and found this 
piece of code:

//
int abc(int delegate(long i));
int def(int function(long s));

void test() {
   int b = 3;
   abc( (long c) { return 6 + b; } );  // inferred to delegate
   def( (long c) { return c * 2; } );  // inferred to function
}
//

On linux machine with [DMD64 D Compiler v2.065] it doesn't 
compile, giving me this error:

test.d(10): Error: function test.def (int function(long s)) is 
not callable using argument types (long function(long c) pure 
nothrow @safe)

Here DMD infers  (long c) { return c * 2; }  as   long 
function(long c).
And "def" definition doesn't match.
Is that an error in the docs, or mayber I'm doing something wrong?





More information about the Digitalmars-d-learn mailing list