boost::function demo
2011-12-31 16:19
134 查看
#include <boost/function.hpp> #include <stdio.h> /******************************************/ class Demo { public: void showDemo(int nDemo); }; void Demo::showDemo(int nDemo) { printf("%d\n",nDemo); } void TestMemberFunction() { boost::function<void (Demo*,int)> f; f = &Demo::showDemo; Demo d; f(&d,2); } /******************************************/ int main(int argc,char* argv) { TestMemberFunction(); } /* A function object f is compatible if for the given set of argument types Arg1, Arg2, ..., ArgN and a return type ResultType, the appropriate following function is well-formed: // if ResultType is not void ResultType foo(Arg1 arg1, Arg2 arg2, ..., ArgN argN) { return f(arg1, arg2, ..., argN); } // if ResultType is void ResultType foo(Arg1 arg1, Arg2 arg2, ..., ArgN argN) { f(arg1, arg2, ..., argN); } */ /* A special provision is made for pointers to member functions. Though they are not function objects, Boost.Function will adapt them internally to function objects. This requires that a pointer to member function of the form R (X::*mf)(Arg1, Arg2, ..., ArgN) cv-quals be adapted to a function object with the following function call operator overloads: template<typename P> R operator()(cv-quals P& x, Arg1 arg1, Arg2 arg2, ..., ArgN argN) const { return (*x).*mf(arg1, arg2, ..., argN); } */
相关文章推荐
- c++ boost function () 语义小猜
- Boost.Function指南
- function invoke objects DEMO
- FunctionDemo2
- boost::function 用法简介
- boost::function的用法
- error: use of deleted function boost::shared_ptr 问题解决
- Boost.Bind和Boost.Function的一种搭配使用法
- Oracle PLSQL Demo - 18.02.管道function[查询零散的字段组成list管道返回] [字段必须对上]
- 为什么使用boost::function绑定类成员函数时,类的析构函数不能为虚函数
- XGBoost Demo
- 以boost::function和boost:bind取代虚函数
- boost::function的用法
- FunctionDemo
- Boost 实用工具:noncopyable、BOOST_BINARY宏、BOOST_CURRENT_FUNCTION宏、bitset类型
- boost::bind 和 boost::function 基本用法
- 151129FunctionDemo
- Oracle PLSQL Demo - 19.管道function[查询整表组成list管道返回]
- error: no matching function for call to ‘boost::thread::thread(<unresolved overloaded function type>
- 以boost::function和boost:bind取代虚函数