.*操作符的用法
2010-11-23 13:27
113 查看
#include <iostream> #include <algorithm> #include <vector> #include <string> using namespace std; class Widget { static int counter; public: Widget() { counter++; cout<<"my id is:"<<counter<<endl; cout<<"this is one day i come to this world"<<endl; } virtual ~Widget() { counter--; cout<<"there 's on day i will leave from this world"<<endl; } void ShowInfor() { cout<<"my id is:"<<counter<<endl; } void Running() { cout<<"i can running fast enough to reach the moon"<<endl; } }; //typedef void (Widget::*fun)() ; int Widget::counter=0; //template<class Function> class function { private: typedef void (Widget::*Fun)(); Fun fun; public: function(Fun fun) { this->fun=fun; } void operator()(Widget *wid) { (wid->*fun)(); } }; void Destroy(Widget *wid) { delete wid; } int main() { vector<Widget*> widgets; for(int i=0; i<10; i++) { widgets.push_back(new Widget()); } for_each(widgets.begin(),widgets.end(),function(&Widget::ShowInfor)); for_each(widgets.begin(),widgets.end(),function(&Widget::Running)); return 0; }
相关文章推荐
- C/C++ sizeof操作符用法详解
- Python原始字符串与Unicode字符串操作符用法实例分析
- c语言操作符用法及总结
- 在C语言中操作符及用法
- SQL集合操作符的用法(Oracle中)
- 关于Python 的@操作符 Decorator 的用法
- C++点和箭头操作符用法区别
- Python 星号(*)操作符的用法
- 浅析C++中sizeof操作符的用法
- C++ sizeof 操作符的用法总结
- 关于python 的@操作符 Decorator 的用法
- SQL中in操作符的用法
- operator的另一种用法:操作符隐式转换
- mongodb 内嵌数组 操作符 $slice 用法
- c++中的各种输入操作符 cin,cin.get(),cin.getline()等函数用法总结
- 操作符“=”的巧妙用法和陷阱
- C++ sizeof 操作符的用法总结
- JavaScript中的typeof操作符用法实例
- C++ sizeof 操作符的用法总结
- RxJava2.0中flatMap操作符用法和源码分析(五)