C++测试Map和Vector实现函数的存储
来源:互联网 发布:ds video windows 编辑:程序博客网 时间:2024/06/05 16:19
#include <vector>
#include <map>
#include <string>
using namespace std;
// 声明一个函数指针
int(*pFunc)(int);
int func1(int nIn){return nIn + 1;}
int func2(int nIn){return nIn + 20;}
typedef int(*pInt)(int);//定义别名才能放在vector中
void main()
{
pFunc = func1;// 把函数名赋给函数指针
int n = pFunc(1);
pFunc = &func2;
n = pFunc(1);
//vector<int(*pFun)(int)> v_pFunc;//不能这样定义
//
vector<pInt> v_pInt;
v_pInt.push_back(func1);
v_pInt.push_back(func2);
int i = v_pInt[0](2);
i = v_pInt[1](2);
//
map<string,pInt> map_pInt;
map_pInt.insert(pair<string,pInt>("key1",func1));
map_pInt.insert(pair<string,pInt>("key2",func2));
int j = map_pInt["key1"](3);
j = map_pInt["key2"](3);
}
#include <map>
#include <string>
using namespace std;
// 声明一个函数指针
int(*pFunc)(int);
int func1(int nIn){return nIn + 1;}
int func2(int nIn){return nIn + 20;}
typedef int(*pInt)(int);//定义别名才能放在vector中
void main()
{
pFunc = func1;// 把函数名赋给函数指针
int n = pFunc(1);
pFunc = &func2;
n = pFunc(1);
//vector<int(*pFun)(int)> v_pFunc;//不能这样定义
//
vector<pInt> v_pInt;
v_pInt.push_back(func1);
v_pInt.push_back(func2);
int i = v_pInt[0](2);
i = v_pInt[1](2);
//
map<string,pInt> map_pInt;
map_pInt.insert(pair<string,pInt>("key1",func1));
map_pInt.insert(pair<string,pInt>("key2",func2));
int j = map_pInt["key1"](3);
j = map_pInt["key2"](3);
}
//之后作者有有一定修改
//vector只能放类型,不能放函数指针变量名
vector<int(*)(int)> v_pFunc;
v_pFunc.push_back(func1);
v_pFunc.push_back(func2);
int k = v_pFunc[0](5);
k = v_pFunc[1](5);
vector<int(*)(int)> v_pFunc;
v_pFunc.push_back(func1);
v_pFunc.push_back(func2);
int k = v_pFunc[0](5);
k = v_pFunc[1](5);
0 0
- C++测试Map和Vector实现函数的存储
- vector和map的erase()函数
- vector和map的erase()函数
- C++MAP和vector的用法
- 测试vector,map存取的小程序
- C语言实现串,和简单的主函数测试
- [C++]vector的存储方式和自增长问题
- vector的实现【C++】
- 关于Vector和Map查找效率的惊人的实际测试结果
- C++存储数据结构List、CArray、Vector和Map使用分析
- c++,vector,map
- C/C++知识要点2——STL中Vector、Map、Set容器的实现原理
- C++STL(vector,map,set,list)成员函数整理
- C变量和函数的存储类型
- C变量和函数的存储类型
- map和vector的查找方法
- map和vector删除元素的区别
- vector和map的erase问题
- android开源项目和框架
- Linux进程间通信
- 新手CrossApp 之CAAlertView小结
- mac下ecplise用真机调试无法识别问题
- 进度条(js实现)
- C++测试Map和Vector实现函数的存储
- Android动态改变GridView的值【安卓进化二十二】
- 换博客了
- Linux常用命令
- Linux中ifconfig命令不显示IP地址
- Linux文件系统的实现
- 360挺进中国搜索No.1 推出独立搜索品牌"好搜
- freemarker 数字输出中的逗号问题
- 观察者模式 Observer