What does it mean to pass a function type parameter in C ++?

And back, I discovered that you can write a C ++ function that takes a function type parameter ( not a function pointer type!). For example, here is a function that takes a callback function that accepts and returns double:

void MyFunction(double function(double)); 

My question is what it means to have a function type variable, since you cannot declare it in any other context. Semantically, how is it different from a function pointer or function references? Is there an important difference between function pointers and function type variables that I should be aware of?

+8
c ++ function types arguments
source share
1 answer

Just as void f(int x[]) matches void f(int* x) , the following two are identical:

 void MyFunction(double function(double)); void MyFunction(double (*function)(double)); 

Or, in the official language (C ++ 03 8.3.5 / 3), when determining the type of function

After determining the type of each parameter, any parameter of the type "array of T " or "function return T " is configured as a "pointer to T " or "pointer to a function return T , respectively.

+13
source share

All Articles