2010-11-19 16 views
1

我有一個[]運算符重載的類。我也有一個線程開始... 如何將[]綁定到線程?Boost :: bind問題綁定重載運算符

我嘗試這樣做:

threadpool.schedule(bind(static_cast< MyClass (MyClass::*)(const MyClass &arg)>(&MyClass::operator[]), arg))

但VS2008說:

錯誤C2664:

'boost::threadpool::thread_pool::schedule': cannot convert parameter 1 from 'boost::_bi::bind_t' to 'const boost::function0 &' 

我該如何解決?先謝謝你。

+0

你能提供'MyClass'代碼嗎? – icecrime 2010-11-19 15:50:40

回答

1

這看起來不對。你的成員函數仍然接受一個參數。所以你需要一個佔位符,或者你忘了綁定this

threadpool.schedule(bind( 
    static_cast< MyClass (MyClass::*)(const MyClass &arg)>(&MyClass::operator[]), 
    this, arg)) 

接受它的類類型看起來有點怪,雖然一個operator[]。這裏是一個例子,它應該如何尋找一個「通常」下標運算符

threadpool.schedule(bind(
    static_cast< MyClass (MyClass::*)(std::size_t)>(&MyClass::operator[]), this, index) 
);