Call a function with a function pointer

Namespace rswhite4 at googlemail.com
Thu Oct 10 10:47:47 PDT 2013


----
import std.stdio;

void foo1(void function(void*) fp) { }
void foo2(void function(int) fp) { }
void foo3(void*) { }

void main()
{
	foo1((void* ptr) => ( assert(ptr is null) ));
	foo2((int a) => ( a + 1 )); /// Fails: Error: function foo2 
(void function(int) fp) is not callable using argument types (int 
function(int a) pure nothrow @safe)
	
	foo1(&foo3);
	
	void foo4(void function(void*) fp) { }
	foo1(&foo4); /// Fails: Error: function foo1 (void 
function(void*) fp) is not callable using argument types (void 
delegate(void function(void*) fp))
}
----
Can someone explain that to me?


More information about the Digitalmars-d-learn mailing list