C++ 如何将参数绑定到boost::function中?

C++ 如何将参数绑定到boost::function中?,c++,boost,boost-bind,boost-function,C++,Boost,Boost Bind,Boost Function,在boost::bind docs()中,“bind获取的参数由返回的函数对象在内部复制和保存”,但是否有办法将参数复制到这些函数对象中 i、 e: #包括 #包括 #包括 使用名称空间std; void doSomthing(std::string str) { } int main() { boost::function func_obj=boost::bind(&doSomthing,“some string”); //如何通过func_obj获取std::string参数(“某

在boost::bind docs()中,“bind获取的参数由返回的函数对象在内部复制和保存”,但是否有办法将参数复制到这些函数对象中

i、 e:

#包括
#包括
#包括
使用名称空间std;
void doSomthing(std::string str)
{
}
int main()
{    
boost::function func_obj=boost::bind(&doSomthing,“some string”);
//如何通过func_obj获取std::string参数(“某些字符串”)?
}

提前感谢。

对于Boost.Function对象,除了调用它之外,实际上没有什么可以做的,这是出于设计。(您可以复制它、销毁它、与NULL进行比较,但仅此而已)

考虑以下代码:

void Foo () {}
void Bar ( int i ) { printf ( "%d", i ); }

boost::function<void(void)> fFoo (Foo);
boost::function<void(void)> fBar = boost::bind (Bar, 23);
voidfoo(){}
空条(inti){printf(“%d”,i);}
boost::函数fFoo(Foo);
boost::function fBar=boost::bind(条,23);
这两个对象被设计成相同的处理方式。它们是相同的类型,行为也相同。boost函数中没有区分它们的机制


有关Boost.Function(和其他地方)中使用的技术的详细描述,请查看Nevin Liber的

您的意思是要从func_objc变量中读取它们?不太可能。是的,这就是我的意思。我们有助推1。现在不是1.35。对不起,只要把它修好,但没什么大不了的。
void Foo () {}
void Bar ( int i ) { printf ( "%d", i ); }

boost::function<void(void)> fFoo (Foo);
boost::function<void(void)> fBar = boost::bind (Bar, 23);