2010-05-11 75 views
1

我正在嘗試使用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!!! 
} 

回答

3

我想你想bind(&MyClass::DoSomething, this, _1, _2)。雖然我沒有增強安裝來測試。

3

您忘記使用參數佔位符。試試這個吧:

boost::function< void(const std::string& , const std::string&) > callback(
    boost::bind(
      &MyClass::DoSomething, 
      this, _1, _2)); 

這個在gcc 4.4.1上編譯時有boost 1.41。

相關問題