typedef函数指针的使用

参考:
https://www.cnblogs.com/guanguangreat/p/6117988.html
http://blog.csdn.net/big_kingwang/article/details/50527790

简单实例:
#include
using namespace std;

//定义一个函数指针
int (*add)(int,int);

//定义一个类型,其变量为函数指针,类型名字为ADD
typedef int (*ADD)(int,int);

//定义一个函数,其类型可以简写成 int()(int,int)
int sum(int a, int b) {
return a+b;
}

int main() {
int a = 5, b = 6;
add = sum;
ADD s = sum;
cout << "sum:" << (sum)(a,b) << endl;
cout << "sum
:" << sum(a,b) << endl;
cout<<"add:"<<(add)(a,b)< cout << "typedef ADD:" << (s)(a,b) << endl;
return 0;
}

你可能感兴趣的:(typedef函数指针的使用)