函数指针数组
2015-12-23 19:49
141 查看
// tas.cpp : Defines the entry point for the console application. // #include "stdafx.h" typedef int (*Funs)(int, int);//利用typedef定义一个函数指针别名 int add(int a,int b){ return a+b; } int mul(int a,int b){ return a*b; } int main(int argc, char* argv[]) { int x,y; void *a[]={add,mul};//定义了指针数组,这里a是一个普通指针 a[0](8,10);//编译错误,指针数组不能用下标的方式来调用函数 Funs tasksArr[]={//定义一个函数指针数组,数组里面有两个函数 add,//第一个函数,注意只有函数名,写成add(8,10)等是错误的 mul//第二个函数 }; x=tasksArr[0](8,10);//调用函数指针数组中的第一个函数 y=tasksArr[1](8,10);//调用函数指针数组中的第二个函数 printf("%d\n%d\n",x,y); return 0; }
可参考http://jingyan.baidu.com/article/d8072ac47ad60fec95cefd31.html
相关文章推荐
- 关于指针的一些事情
- Mootools 1.2教程 函数
- autoit InputBox 函数
- 文件遍历排序函数
- Oracle 函数大全[字符串函数,数学函数,日期函数]第1/4页
- ASP下经常用的字符串等函数参考资料
- PostgreSQL教程(五):函数和操作符详解(1)
- DOS批处理 函数定义与用法
- asp Chr 函数 数字转字母的方法
- Lua中的函数精讲笔记
- Lua中的闭合函数、非全局函数与函数的尾调用详解
- Lua中调用C++函数示例
- Lua实现split函数
- Lua常用时间函数使用实例
- Lua函数与字符串处理简明总结
- Lua学习笔记之表和函数
- Lua中实现sleep函数功能的4种方法
- Lua函数用法研究
- Lua基础教程之赋值语句、表达式、流程控制、函数学习笔记
- PowerShell函数简明教程