0
我試圖將運行一對夫婦的那類的內部函數的類的構造函數來創建線程,我已經試過這樣:線程在構造函數,C++
ServerLogic::ServerLogic(SOCKET sock)
{
this->sock = sock;
this->dispatchThread = new std::thread(this->dispatchMessage);
}
void ServerLogic::dispatchMessage(){
/*
* this function will handle the connetions with the clients
*/
char recievedMsg[1024];
int connectResult;
//receive data
while (true){
connectResult = recv(this->sock, recievedMsg, sizeof(recievedMsg), 0);
//in case everything good send to diagnose
if (connectResult != SOCKET_ERROR){
this->messagesToDiagnose.push(std::string(recievedMsg));
}
else{
/*
* destructor
*/
}
}
}
,但它給我一個錯誤: 'ServerLogic :: dispatchMessage':函數調用缺少參數列表;使用'& ServerLogic :: dispatchMessage'來創建一個指向成員的指針。 (在C:\ Program Files(x86)\ Microsoft Visual Studio 12.0 \ VC \ include \ thread的第70行中聲明的智能感知函數「std :: thread :: thread(const std :: thread &)」) 「)不能被引用 - 它是一個被刪除的函數。
你混淆'dispatchThread'用'dispatchMessage'? – nwp
是的,請參閱更新 – etamar211
錯誤說這是所有 - 這將是你的拳頭解決。修復之後,您將會遇到另一個錯誤 - 請參閱是否可以修復它。 – SergeyA