A pointer to a function points to the address of the executable code of the function. You can use pointers to call functions and to pass functions as arguments to other functions. You cannot perform pointer arithmetic on pointers to functions.
The type of a pointer to a function is based on both the return type and parameter types of the function.
int *f(int a); /* function f returning an int* */
int (*g)(int a); /* pointer g to a function returning an int */
In the first declaration, f is interpreted as a function that takes an int as argument, and returns a pointer to an int. In the second declaration, g is interpreted as a pointer to a function that takes an int argument and that returns an int.
auto(*fp)()->int;
In
this example, fp is a pointer to a function that
returns int. You can rewrite the declaration of fp without
using a trailing return type as int (*fp)(void).
For more information on trailing return type, see Trailing return type (C++11).int g();
// f is a reference to a function that has no parameters and returns int.
int bar(int(&f)()){
// call function f that is passed as an argument.
return f();
}
int x = bar(g);
auto(&fp)()->int;