typedef int (*func)(int);
定义了一种函数指针的类型。
类型名为 func
类型为 返回值为 int 类型,参数为 int 类型的函数指针。
下面代码为一种用法:
typedef int (*func)(int);int getvalue(int a){return a*a;}int getvalue1(int a){return a*a*a;}int getvalue2(int a){return a*a*a*a;}func f= &getvalue;int a = (*f)(2);cout<<"a= "<<a<<endl;func fun[]={&getvalue,&getvalue1,&getvalue2};for (int i=0;i<3;i++){func fu = fun[i];cout<<(*fu)(3)<<endl;cout<<fu(3)<<endl;}