您的位置:首页 > 移动开发 > Objective-C

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);
}
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息