函数指针的用法

 

#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;
}

posted @ 2009-01-21 23:28  谭志宇  阅读(226)  评论(0编辑  收藏  举报