gpt4 book ai didi

c++ - 术语不计算为采用 1 个参数的函数

转载 作者:行者123 更新时间:2023-11-28 05:06:26 25 4
gpt4 key购买 nike

所以我一直在使用多线程编写一些客户端服务器代码,我编写了这个函数:

void TriviaServer::accept()
{
// this accepts the client and create a specific socket from server to this client
SOCKET client_socket = ::accept(_socket, NULL, NULL);

if (client_socket == INVALID_SOCKET)
throw std::exception(__FUNCTION__);
// make a thread that will handle the new client
std::thread t(&TriviaServer::clientHandler, this, client_socket);
t.detach();
}

Visual Studio 说问题是:

error c2064: term does not evaluate to a function taking 1 argument

我知道有一个问题与我给出的名称相同,但我没有在答案中看到解决方案。

Handle Client 函数由以下行声明:

void clientHandler(SOCKET);

我改行后出现的错误:

std::thread t(&TriviaServer::clientHandler, this, client_socket);

这个函数在每次接受新客户端并用 clientHandler 处理他时被无限调用,这个函数位于名为 TriviaServer 的类中。

最佳答案

std::exception's constructor不采用 const char*std::string 作为参数。您将不得不使用另一个异常类,例如 std::runtime_error ,它提供了这样一个构造函数。

如果需要,您也可以提供自己的异常类。

关于c++ - 术语不计算为采用 1 个参数的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44634727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com