A while back I found that it's possible to write a C++ function that takes a parameter of function type (not function pointer type!). For example here's a function that takes a callback function that accepts and returns a double:
void MyFunction(double function(double));
My question is what it means to have a variable of function type, since you can't declare one in any other context. Semantically, how is it different from a function pointer or reference to a function? Is there an important difference between function pointers and variables of function type that I should be aware of?
Just like void f(int x[]) is the same as void f(int* x), the following two are identical:
void MyFunction(double function(double));
void MyFunction(double (*function)(double));
Or, in official language (C++03 8.3.5/3), when determining the type of a function,
After determining the type of each parameter, any parameter of type "array of
T" or "function returningT" is adjusted to be "pointer toT" or "pointer to function returningT," respectively.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With