이 내가 서버 응답을받을 스레드를 사용하고자하지만, 작은 소켓 데모 주요 파일 나는 새로운 스레드를 만들려고 할 때 :오류 ++ THEAD
오류 메시지 :
error: no matching constructor for initialization of 'std::thread'
코드를 :
#include <iostream>
#include <thread>
#include "client_socket.h"
#include "socket_exception.h"
void receive(ClientSocket client)
{
std::string reply;
while (true) {
client >> reply;
std::cout << "We received this response from the server:" << std::endl;
std::cout << "\"" << reply << "\"" << std::endl;
}
}
int main(int argc, const char* argv[])
{
try {
ClientSocket client("127.0.0.1", 30000);
std::string sendBuf;
std::thread receiver(receive, client);
receiver.join();
while (true) {
std::cout << "Enter string send to server:" << std::endl;
std::cin >> sendBuf;
if (sendBuf.compare("quit") == 0) {
break;
}
try {
client << sendBuf;
} catch (SocketException&) {}
}
} catch (SocketException& e) {
std::cout << "Exception was caught:" << e.description() << std::endl;
}
return 0;
}
사용 된 스레드에 문제가 있습니까? 덕분에
어떤 컴파일러를 사용하고 있습니까? 이것은 [working ..] (http://coliru.stacked-crooked.com/a/8d14a8f14cc6f660)이어야합니다. –
'ClientSocket' copy가 생성 가능합니까? – Sean
@Sean 그렇지 않은 경우 스레드 생성자는 여전히 일치하는 singature를 갖지만 스레드 인수가 생성자 내부에서 복사되는 부분을 컴파일하는 데 실패합니다. 다른 오류 메시지가 표시됩니다. –