我有以下問題。C++多線程類方法
vector<thread> vThreads;
list<Crob *> lRobs;
list<Crob *>::iterator i;
for(i = lRobs.begin(); i != lRobs.end(); i++)
{
vThreads.push_back(thread((*i)->findPath));
}
我想的方法findPath傳遞給一個線程,但我得到了很多的錯誤......
> labrob.cpp: In function ‘int main(int, char**)’:
labrob.cpp:72:43: error: no matching function for call to ‘std::thread::thread(<unresolved overloaded function type>)’
labrob.cpp:72:43: note: candidates are:
In file included from labrob.cpp:14:0:
/usr/include/c++/4.7/thread:131:7: note: std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = int (Crob::*)(); _Args = {}]
/usr/include/c++/4.7/thread:131:7: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘int (Crob::*&&)()’
/usr/include/c++/4.7/thread:126:5: note: std::thread::thread(std::thread&&)
/usr/include/c++/4.7/thread:126:5: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘std::thread&&’
/usr/include/c++/4.7/thread:122:5: note: std::thread::thread()
/usr/include/c++/4.7/thread:122:5: note: candidate expects 0 arguments, 1 provided
make: *** [labrob.o] Error 1
我已經嘗試通過本地功能和無的問題,工作。 .. 如果您需要額外的代碼片段,請說。
我希望有人能幫助我。
編輯:
#pragma once
包括 「point.hpp」
包括 「lab.hpp」
類Crob { 保護: 口岸系統* POS機; int steps; Clab * labfind; 弦方向;
public: Crob(Clab * lab);虛擬〜Crob(); virtual void findPath(); void moveTo(int x,int y);
void moveToPrint(int x,int y); int getSteps(void); void checkDirection(); };
新增CRob頭
'Crob'是什麼定義? –
你應該使用'std :: bind()'將這個方法傳遞給線程。 –