參見<<c++ primer>> p237頁
bool (*pf)(const string &, const string &);
typedef bool (*cmpFcn) (const string &,const string &);//表示cmpFcn是一種指向函數的指針類型的名字
bool lengthCompare(const string &,const string &){return 0;}
int main()
{
cmpFcn pf1 = 0;//函數指針初始化爲0表示該指針不指向任何函數
cmpFcn pf2 = lengthCompare;
pf2 = pf1;
pf1 = lengthCompare;
pf2 = &lengthCompare;//在函數名上應用取地址操作符 等效於 直接引用函數名
lengthCompare("hi","bye");
(*pf2)("hi","bye");
pf1("hi","bye");//可以不需要使用解引用操作符,直接通過指針調用函數
return 0;
}
void useBigger1(const string &,const string &,bool(const string&,const string&) );//函數指針作形參的兩種形式
void useBigger2(const string &,const string &,bool (*)(const string&,const string&) );