[C++] boost::function boost::bind 与 回调
2017-09-02 21:47
429 查看
boost::function 和 boost::bind
boost::function是对函数指针的对象化封装,是一个函数对象的容器,在概念上与回调函数类似,先看一个例子:#include <boost/function.hpp> #include <boost/bind.hpp> #include <iostream> class TestA { public: void method() { std::cout << "TestA: method: no arguments" << std::endl; } void method(int a, int b) { std::cout << "TestA: method: with arguments" << "value of a is:" << a << "value of b is:" << b << std::endl; } }; void sum(int a, int b) { int sum = a + b; std::cout << "sum: " << sum << std::endl; } int main() { boost::function<void()> f; TestA test; f = boost::bind(&TestA::method, &test); f(); f = boost::bind(&TestA::method, &test, 1, 2); f(); }
boost::function通常结合boost::bind一起使用,这是因为bind返回的正好是一个函数对象。
相关文章推荐
- boost 11 function/bind 函数与回调
- C++ boost bind与 boost function的使用
- 现代C++的回调技术--使用std::bind和std::function
- C++中std::tr1::function和bind 组件的使用 和 以boost::function和boost:bind取代虚函数
- 对比基于boost::function/bind和AS3 Function回调机制
- 【C++】bind+function的回调机制
- C++中std::tr1::function和bind 组件的使用
- 编程模仿boost::function和boost::bind
- C++_std::bind std::function 高级用法
- 以boost::function和boost:bind取代虚函数
- 一个类里可以注册不同类型的消息及boost:function和boost:bind的使用
- 关于boost::function与boost::bind函数的使用心得
- C++ 类的成员函数指针 ( function/bind )
- boost : ref , bind , function
- c++中的std::bind与std::function
- 在c++中用function与bind实现委托
- <转载+个人总结>以boost::function和boost:bind取代虚函数
- 以boost::function和boost:bind取代虚函数
- C++ function、bind以及lamda表达式
- C++中std::tr1::function和bind 组件的使用