Skip to main content
gamedev.net
🔒 Locked

pointers to functions

Started by bilstonwarrior Sep 11, 2003 at 11:18 AM 3 replies 350+ views
Original Post
bilstonwarrior
bilstonwarrior
hi. i have the following code: void Testfunction(int a, int b); void Testfunction(int a, int b) { printf("HELLO %d %d",a,b); } i call this in my main loop: AddFunctionPointer("POINTER_TO_TEST", &Testfunction); this is the declaration for: AddFunction(char TextString[40], void (*value)()) { // store the pointer to the function } I know i havnt fully explained it all but i guess u get where i am coming from... right, this works fine if i dont have parameters (a & b) in "TestFunction". If i have parameters in Testfunction as above then i get the compile error: --------------------- Error : function call AddFunction({lval} const char[11], void (*)(int, int))'' does not match ''AddFunction(char *, void (*)())'' (non-static) main.cpp AddFunction("THIS_FUNCTION", &Testfunction); ---------------------- PLEASE HELP!! thanks Paul.
dagarach
dagarach

As the error message says, "&Testfunction" is not of type "void (*value)()"

function pointers are strongly typed, just the same as objects.

bilstonwarrior
bilstonwarrior
so how to i make it so i can have a pointer to a function with say 2 parameters?
dagarach
dagarach
http://www.function-pointer.org/
mputters
mputters


void Testfunction(int a, int b);


void Testfunction(int a, int b)
{
printf("HELLO %d %d",a,b);
}


i call this in my main loop:

AddFunctionPointer("POINTER_TO_TEST", &Testfunction);




this is the declaration for:
AddFunction(char TextString[40], void (*value)( int, int ))
{
// store the pointer to the function

}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.