函数指针的用法

#include <iostream>
using namespace std;
int fun(int a)
{
 return a;
}

typedef int(*funname)(int a);

//对照DELPHI

// type

//     funname = function(a: integer): int;

//

//函数指针数组

//typedef
//  int(*funarray[3])(int a);

int main()
{
 int (*test[1])(int a) = {fun}; //函数指针数组
 cout<<test[0](2)<<endl;
 funname test1 = fun; //使用和DELPHI差不多
 cout<< test1(3)<<endl;

 //调用

 funarray test2 = {fun};
 cout<<test2[0](4)<<endl; //DELPHI里没见人这么用过

 return 0;
}

原文地址:https://www.cnblogs.com/chengxin1982/p/1379675.html