map管理成员函数指针
来源:互联网 发布:物联网编程技术 编辑:程序博客网 时间:2024/05/17 04:46
转自:http://bbs.csdn.net/topics/290032347
概括:将成员函数指针名和同名的string类型的变量名进行绑定,插入到map中。
在使用时就可以通过找到string类型的变量名来使用同名的函数
#include "iostream"#include "string"#include "map"using namespace std;class test{public : void fun1() { cout<<"call test::fun1"<<endl; } void fun2() { cout<<"call test::fun2"<<endl; } void fun3() { cout<<"call test::fun3"<<endl; } test() { m_mapFun["test::fun1"] = &test::fun1; m_mapFun["test::fun2"] = &test::fun2; m_mapFun["test::fun3"] = &test::fun3; } void call(string strfun) { if (m_mapFun.find(strfun) == m_mapFun.end()) cout<<"no function : "<<strfun<<endl; else (this->*m_mapFun[strfun])(); }protected : typedef void (test::*mfun)(); map<string, mfun> m_mapFun;};int main(){ test t; t.call("test::fun1"); t.call("test::fun2"); t.call("test::fun3"); t.call("test::fun4"); return 0;}-----------------结果:call test::fun1call test::fun2call test::fun3no function : test::fun4
0 0
- map管理成员函数指针
- 成员函数指针, 实现handler map
- 使用成员函数管理map STL
- 析构函数 管理指针成员
- 13.5 管理指针成员
- 管理指针成员
- 管理指针成员
- C++管理指针成员
- c++ 管理指针成员
- 管理指针成员
- C++管理指针成员
- 管理指针成员
- 管理指针成员
- 函数指针 成员函数指针
- 成员函数指针【转贴】
- 类成员函数指针
- 成员函数指针数组
- 成员函数 指针
- 小记——内存映射
- hdu5722Jewelry
- strlen递归实现
- iOS9 HTTP 不能正常使用的解决办法
- 最近想开始学习机器学习
- map管理成员函数指针
- 读取文件方法大全
- zencart 本地环境使用ip访问无法登陆的问题
- Memcache[3]telnet操作Memcached
- Hadoop基础之MapReduce原理、序列化和源码分析
- c#中Dictionary、ArrayList、Hashtable和数组的区别是什么
- mpi学习日志(3):mpi4py与广播
- 我的linux菜鸟之路2
- android recycleView的进一步封装