看下面的例子:
// ptrFunc is the name of the pointer to the getFunction
void* (*ptrFunc)(void*, void*) = &getfunction;
// ... Declaring whatever lib and fname are
// Now call the actual function by using a pointer to it
ptrFunc(lib, fname);
// Another form of how to call getFunc might be :
(*ptrFunc)(lib, fname);
此外,您可以将函数指针传递给另一个函数,例如:
void *getFunction(void* lib, void* fname)
{
// Whatever
}
void myFunction( void* (*ptrFunc)(void*, void*) )
{
// void *lib = something;
// void *fname = something else;
ptrFunc(lib, fname);
}
int main()
{
void* (*ptrFunc)(void*, void*) = &getfunction;
// Passing the actual function pointer to another function
myFunction(ptrfunc);
}