boost::function demo

#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);
  }
  */



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值