【VC开源代码栏目提醒】:网学会员VC开源代码为您提供FunPtrArray.cpp参考,解决您在FunPtrArray.cpp学习中工作中的难题,参考学习。
// FunPtrArray.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int sum(int x,int y) //定义求和函数
{
return x + y;
}
int sub(int x,int y) //定义减法函数
{
return x - y;
}
int mul(int x,int y) //定义乘法函数
{
return x * y;
}
int divi(int x,int y) //定义除法函数
{
return x / y;
}
int main(int argc, char* argv[]) //主函数
{
int (*ptfun[4])(int,int); //定义函数指针数组
ptfun[0] = sum; //为数组中的元素赋值
ptfun[1] = sub;
ptfun[2] = mul;
ptfun[3] = divi;
for(int i=0; i<4; i++) //利用循环遍历数组
{
int ret = ptfun[i](30,10); //调用当前函数指针指向的函数
printf("%d\n",ret); //输出结果
}
return 0;
}
上一篇:
frmSetTime.frm
下一篇:
基于消费者社会化视角的儿童消费者影响因素研究