现在的位置: 首页 > 综合 > 正文

函数指针

2018年06月06日 ⁄ 综合 ⁄ 共 321字 ⁄ 字号 评论关闭
本文着重介绍函数指针,此处的用法也许可用于实现c语言的面相对象编程。
#include <afx.h>
void hello()
{
printf("hello");
}

void good()
{
printf("good");
}
void same()
{
printf("same");
}

typedef void  (* funcPtr)();

int main()
{
#if 1
void  (* ptr[3])()={hello,good,same};
#else
funcPtr ptr[3] = {hello,good,same};
#endif
funcPtr pp;
for(int i=0;i<3;i++)
{
pp = ptr[i];
(*pp)();
}
system("pause");
return 0;
}

抱歉!评论已关闭.