所以我想创建一个像:
这样的函数void proxy_do_stuff(boost::bind return_here)
{
return_here(); // call stuff pased into boost::bind
}
我可以称之为:
proxy_do_stuff(boost::bind(&myclass::myfunction, this, my_function_argument_value, etc_fun_argument));
怎么做这样的事情?
答案 0 :(得分:4)
boost :: bind的返回类型是boost :: function类型。见下文:
void proxy_do_stuff(boost::function<void()> return_here)
{
return_here(); // call stuff pased into boost::bind
}
答案 1 :(得分:3)
#include <boost/bind.hpp>
template<typename T>
void proxy_do_stuff(T return_here)
{
return_here(); // call stuff pased into boost::bind
}
struct myclass
{
void myfunction(int, int)
{
}
void foo()
{
int my_function_argument_value = 3;
int etc_fun_argument= 5;
proxy_do_stuff(boost::bind(&myclass::myfunction, this, my_function_argument_value, etc_fun_argument));
}
};
int main()
{
myclass c;
c.foo();
return 0;
}