2010-07-13 75 views
1

下面的代码在罚球线一个错误的位置我想创建的Test::fun2仿函数对象:有问题的boost ::绑定

#include <boost/shared_ptr.hpp> 
#include <boost/bind.hpp> 
#include <boost/function.hpp> 

using namespace boost; 

class Test 
{ 

public: 
float fun1() { return 0.0f; } 
void fun2(float x) {} 

}; 

int main(int argc, char* argv[]) 
{ 

shared_ptr<Test> p = shared_ptr<Test>(new Test); 

function<float(void)> f1 = bind(&Test::fun1, p); 
function<void(float)> f2 = bind(&Test::fun2, p); 

return 1; 

} 

编译器给了我一套模板的错误和

`void (Test::*)(float)' is not a class, struct, or union type 

这似乎是主要的错误。不过,我不知道这里有什么问题以及如何解决。

回答

2

问题解决:我使用了错误的语法。

function f2 = bind(& Test :: fun2,p,_1);

工程。

+1

你可以接受你自己的答案。 – 2010-08-02 01:22:59

+0

问题的标题有点欠缺! – Ant 2012-07-05 09:13:17