Pointer to a function?
How do you create a pointer to a function? I think I saw this explained once but I can''t find where it was
I asked some stuff about function pointers a few days ago. Here is a link to the posts.
Click me Somebody said how to make them in there.
Drakonite
[Insert Witty Signature Here]
Click me Somebody said how to make them in there.
Drakonite
[Insert Witty Signature Here]
Shoot Pixels Not People
This way:
RETURN_TYPE (FUNCTION_NAME)(PARAMETERS_TYPE)
Example:
int Foo(int i);
int Foo2(int i);
int (pFunc)(int);
pFunc=Foo;
pFunc(69);//Execute Foo()
pFunc=Foo2;
pFunc(666);//Execute Foo2
What the hells!
What the hells!
Great, that helps a lot.
Another question though...
How would I pass that pointer to a function?
What I am trying to do is pass a pointer to a function - to a function like this:
Create(WINDOW, etc, etc, etc, POINTER_TO_A_FUNCTION)
{
variable_to_receive_function_pointer = POINTER_TO_A_FUNCTION;
// etc
}
This way I can have a class store the pointer to this function and call that function whenever I need it.
Can anyone give a straight example of how I would denotate that? The function will ALWAYS return void and will ALWAYS have no parameters
Another question though...
How would I pass that pointer to a function?
What I am trying to do is pass a pointer to a function - to a function like this:
Create(WINDOW, etc, etc, etc, POINTER_TO_A_FUNCTION)
{
variable_to_receive_function_pointer = POINTER_TO_A_FUNCTION;
// etc
}
This way I can have a class store the pointer to this function and call that function whenever I need it.
Can anyone give a straight example of how I would denotate that? The function will ALWAYS return void and will ALWAYS have no parameters
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement