2016-01-08 46 views
1

我正嘗試用線程創建一個數組。我的代碼如下所示:C++中的線程數組Boost

boost::thread threads[10]; 

    for(int i = 0; i < 10; i++){ 
     client c(io_services[i], "www.boost.org", "/"); 

     threads[i] (boost::bind(workerFunc, i)); 

    } 

而且我得到的編譯錯誤:

error: no match for call to ‘(boost::thread) (boost::_bi::bind_t<void, void (*)(int), boost::_bi::list1<boost::_bi::value<int> > >)’ 
     threads[i] (boost::bind(workerFunc, i)); 

我想不出什麼,我需要在我的代碼更改。任何幫助將不勝感激。

+0

你包括升壓頭? [檢查此](http://www.boost.org/doc/libs/1_60_0/more/getting_started/index.html)以獲取更多信息 –

+0

@JamesKirsch是的我是 – andrey

+0

線程構造函數在內部使用綁定。嘗試線程[我](&some_function); – aayush93

回答

4

您正在尋找:

boost::thread threads[10]; 

for(int i = 0; i < 10; i++){ 
    client c(io_services[i], "www.boost.org", "/"); 

    threads[i] = boost::thread(boost::bind(workerFunc, i)); 
} 
+1

謝謝,幫助! – andrey