解决VC6无法为STL的for_eash绑定函数内部类的问题
2012-07-10 23:48
519 查看
VC6里无法为STL的for_eash绑定函数内部类,貌似因为for_eash用到了模板, 而当时版本的模块只能支持全局类。
解决如下:
通过两个全局类和函数的多态机制绕开模板只支持全局类的问题。
解决如下:
#include <iostream> #include <vector> #include <algorithm> using namespace std; #define AUTO_CLASS_COUNT template<class _T> struct bass_fun { virtual void operator()(_T& _p) { cout<<"old "<<_p<<endl; } }; template<class _T> struct bind_fun { bind_fun(bass_fun<_T>* _fun) { m_fun = _fun; } virtual void operator()(_T& _p) { (*m_fun)(_p); } bass_fun<_T> *m_fun; }; void main() { vector<int> m_v_viewboxmgr; for(int i=0; i<10; i++) m_v_viewboxmgr.push_back(i); struct Fun:public bass_fun<int> { virtual void operator()(int& _p) { cout<<"new "<<_p<<endl; } }; Fun fun; for_each(m_v_viewboxmgr.begin(), m_v_viewboxmgr.end(), bind_fun<int>(&fun)); system("pause"); }
通过两个全局类和函数的多态机制绕开模板只支持全局类的问题。
相关文章推荐
- 解决spring aop无法拦截代理内部函数调用的问题
- 采用自执行的匿名函数解决for循环使用闭包的问题
- ABP学习 解决:Update-Database : 无法将“Update-Database”项识别为 cmdlet、函数、脚本文件或可运行程序的名称的问题
- MySQL无法登录问题-"ERROR 1045 (28000): Access denied for user 'root'@'localhost'"-之解决方法-密码重置
- “VS2003调试时无法跟踪函数”问题解决方法
- 问题解决:printf()函数无法打印
- [拦截器]关于拦截方法调用其他内部方法无法被拦截问题的解决
- Spring3中js/css/jpg/gif等静态资源无法找到(No mapping found for HTTP request with URI)问题解决
- 完美解决ListView内部嵌套GridView导致各种异常,无法点击的问题
- ArcGis for android 的HelloWorld的应用无法加载地图的问题的解决
- 解决DataGridView绑定了数据源无法更新保存当前行的问题
- Spring3中js/css/jpg/gif等静态资源无法找到(No mapping found for HTTP request with URI)问题解决
- 解决sublimeText3无法安装插件有关问题 - There are no packages available for installation
- spread连接mysql,中文列名无法绑定的问题解决
- Android结合robotium实现自定义waitForText(String text),解决控件无法找到问题
- VC6无法打开文件问题解决,与office2007冲突
- Spring3中js/css/jpg/gif等静态资源无法找到(No mapping found for HTTP request with URI)问题解决
- 解决OpenCV的imread函数无法读取中文路径和中文命名的文件的问题。
- Linux内核模块导出后无法调用问题解决(模块间函数调用通讯)
- 关于Zend Studio for eclipse 6.0 无法启动的问题解决方法