作者popo4231 (小泰)
看板EE_DSnP
標題[問題] function pointer
時間Sun Dec 16 11:52:05 2007
想問一下function pointer解參考之後是什麼東西
我試著將funtion ptr前面放很多個*結果好像並不會error
而且作用上並沒有問題
code:
#include<iostream>
using namespace std;
int add(int a,int b)
{
return a+b;
}
int sub(int a,int b)
{
return a-b;
}
int addorsub(int a,int b,int (*operate) (int,int)) // function pointer
{
return operate(a,b);
}
int main()
{
int (*FUNPTR[2])(int,int)={add,sub};
cout<<(*****FUNPTR[0])(10,5)<<endl;
cout<<(*add)(10,5)<<endl;
cout<<(**add)(10,5)<<endl; // 到底function pointer解參考之後是啥東西 ?
cout<<addorsub(5,3,FUNPTR[0])<<endl;
cout<<addorsub(5,3,FUNPTR[1])<<endl;
system("pause");
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.241.177
1F:→ ilway25:另外我發現一般變數好像不能用超過2個* ?? 12/16 14:25