我正在尝试将boost::bind
与boost::function
一起使用。
这似乎是一个微不足道的例子,但我无法使其发挥作用。你能救我吗?
是因为不允许或我做错了吗?
// .h
class MyClass{
publc:
void DoSomething(
const std::string& a,
const std::string& b);
void DoABind();
}
//.cpp
void MyClass::DoABind(){
boost::function< void( const std::string& , const std::string& ) > callback(
boost::bind(
&MyClass::DoSomething,
this ));
// this line doesn't compile!!!
}
答案 0 :(得分:3)
我想你想要bind(&MyClass::DoSomething, this, _1, _2)
。我没有使用boost进行测试。
答案 1 :(得分:3)
您忘记使用参数占位符。试试这个:
boost::function< void( const std::string& , const std::string& ) > callback(
boost::bind(
&MyClass::DoSomething,
this, _1, _2 ));
这在gcc 4.4.1上编译,增强1.41。