天天看點

看書小記5(《C專家程式設計》)

 函數指針

1. 函數與函數指針類型要比對;

2. 函數指針用來儲存函數首位址,即可以通過該指針通路函數;

3. 函數指針可以指向一類函數,而不是一個函數,即可以重新指派。

int maxnumber(int a, int b)

{

return a > b? a: b;

}

void filefunc(){ cout<<"filefunc"<<endl; }

void editfunc(){ cout<<"editfunc"<<endl; }

int (*intfunc)(int a, int b);

intfunc = maxnumber;

cout<<intfunc(3, 2)<<endl;

void (*voidfunc)();

voidfunc = filefunc;

voidfunc();

voidfunc = editfunc;

參考連結:http://www.cnblogs.com/anwcq/p/c_zhizhenhanshu.html