1、用typedef简化函数指针的定义
typedef bool (*cmpFcn)(const string &, const string &);
cmpFcn p1;//p1是函数指针
2、函数指针形参
void useBigger(const string &s1, const string &s2, bool(*pf)(const string &, cosnt string &));
3、返回指向函数的指针
声明:
int (*ff(int x))(int *, int);//定义里面返回函数的指针也不用指明变量名。ff是一个函数,有一个形参x,返回结果是函数指针int(*)(int *, int)
或
typedef int(*PF)(int *, int);
PF ff(int x);
调用:
int a;
ff(2)(&a,a);
4、指向重载函数的指针
指向重载函数的指针要求形参、返回值精确匹配。