www.digitalmars.com         C & C++   DMDScript  

D - function pointers not working

reply curtis <curtis_member pathlink.com> writes:
Whenever I try to use function pointers (both the c and d way) or delegates I
get an error like the following:
C:\projects\dsamples>dmd functionpointers.d
functionpointers.d(9): cannot implicitly convert int to int(*)()
which is what I get when I compile the following code (which is taken directly
from the manual):

int function() fp;

void test()
{   static int a = 7;
static int foo() { return a + 3; }

fp = foo;
}

void bar()
{
test();
int i = fp();	// i is set to 10
}

int main(char[][] args)
{
test();

return 0;
}
thx curtis
Nov 24 2003
parent "Charles Sanders" <sanders-consulting comcast.net> writes:
fp = &foo;

Docs need updating.

C
"curtis" <curtis_member pathlink.com> wrote in message
news:bpubm0$58g$1 digitaldaemon.com...
 Whenever I try to use function pointers (both the c and d way) or

 get an error like the following:
 C:\projects\dsamples>dmd functionpointers.d
 functionpointers.d(9): cannot implicitly convert int to int(*)()
 which is what I get when I compile the following code (which is taken

 from the manual):

 int function() fp;

 void test()
 {   static int a = 7;
 static int foo() { return a + 3; }

 fp = foo;
 }

 void bar()
 {
 test();
 int i = fp(); // i is set to 10
 }

 int main(char[][] args)
 {
 test();

 return 0;
 }
 thx curtis

Nov 24 2003