开发者

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

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开发者_如何学Go 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 returning T" is adjusted to be "pointer to T" or "pointer to function returning T," respectively.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜