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