作者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