C++学习 boost学习之-function
来源:互联网 发布:vue.js createelement 编辑:程序博客网 时间:2024/05/21 21:33
要点:
1 用于保存函数对象,本身是函数对象
2 与bind一起使用,威力巨大:
class command { boost::function<void()> f_;public: command() {} command(boost::function<void()> f):f_(f) {} void execute() { if (f_) { f_(); } } template <typename Func> void set_function(Func f) { f_=f; } bool enabled() const { return f_; }};
int main() { tape_recorder tr; command play(boost::bind(&tape_recorder::play,&tr)); command stop(boost::bind(&tape_recorder::stop,&tr)); command forward(boost::bind(&tape_recorder::stop,&tr)); command rewind(boost::bind(&tape_recorder::rewind,&tr)); command record; // 从某些GUI控制中调用... if (play.enabled()) { play.execute(); } // 从某些脚本客户端调用... stop.execute(); // Some inspired songwriter has passed some lyrics std::string s="What a beautiful morning..."; record.set_function( boost::bind(&tape_recorder::record,&tr,s)); record.execute();}
3 Boost.Function 也可与Boost.Lambda一起使用
总结,function与bind一起使用的作用之大用语言已无法说完全说明!禅/道在心中!
0 0
- boost学习之function
- boost学习之-function
- C++学习 boost学习之-function
- boost::function学习
- Boost学习之Boost简介
- 【boost学习】之boost::bind
- boost学习之Boost.Lambda
- Boost程序库学习-bind与function
- 学习boost之lexical_cast
- 学习boost之format
- 学习boost之filesystem
- boost之spirit学习
- boost学习之-scoped_ptr
- boost学习之-scoped_array
- boost学习之-shared_ptr
- boost学习之-shared_array
- boost学习之-intrusive_ptr
- boost学习之-weak_ptr
- poj 2104 区间第K小 主席树入门题
- info.plist文件中各键的含义,留着用
- T3升级U8报错相关问题解决方案:
- Unity摄像机的使用四:望远镜的效果
- [转载]Z-stack 应用程序编程接口(API)-网络层
- C++学习 boost学习之-function
- opencv中实现滚动条随着视频播放移动(回调函数)
- Java 通过HttpRequest获取请求用户真实IP地址
- kali mysql重置密码
- SIT与UAT的分别
- Android中Textview显示带html文本一-------【HTML标签】
- APP Store Review Guidelines 中文版-下部
- 安装sphinx(三)
- OpenGL--粒子系统