2010-07-13 69 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