指针指的是一个类型,function’s type is determined by return type and the types of its parameters.
==Pointers to Functions are Similar to Pointers to Arrays
可以类比着去记==
Declaration
just in place of function name. 而且跟数组指针有点像的,要加括号
bool (*pf)(const string &, const string &);
当要指向的函数是一组重载函数,那么也是同理的,要匹配return type和para type
Use
【先说结论】把这个指针直接拿来用就可以了,de不de的都可以。
当我们直接使用函数名作为值的时候,会自动转化为函数指针:
pf = lengthCompare;
pf = &lengthCompare; // equivalent
同样的,直接把指针拿过来直接就能用:
bool b1 = pf("hello", "goodbye");
bool b2 = (*pf)("hello", "goodbye"); // equivalent
bool b3 = lengthCompare("hello", "goodbye"); // equivalent
Function Pointer Parameters
Return a Pointer to Function
【直接】因为我们是把函数名和call一起赋值了作为return的效果,所以是囊括进去写的
int (*f1(int))(int*, int);
Shortcuts by decltype
decltype(f) *ff();
Shortcuts by auto
auto ff() -> int(*)(int);