我想請教一下指針在C++C++指針功能,初學者問
我有一些簡單的代碼:
int add(int a, int b){
return a+b;
}
int runner(int x,int y, int (*functocall)(int, int)){
return (*functocall)(x,y);
}
現在,假設我把使用這樣的功能:
cout<<runner(2,5,&add);
也許
cout<<runner(2,5,add);
有什麼區別?因爲當我嘗試時,結果是一樣的,沒有錯誤。
非常感謝
所以你的意思是,第二個電話是正確的? – BobAlmond 2010-04-06 17:20:45
不,我的意思是說,編譯器解析了對函數指針的調用,這實際上是一個語法偏好問題。 – 2010-04-06 17:22:44