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

term does not evaluate to a function taking 1 argument

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

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 处理他时,此函数被调用 infinity,此函数位于 class 中,称为 TriviaServer。

std::exception's constructor doesn't take a const char* or a std::string as parameter. You will have to use another exception class, like std::runtime_error,它提供了这样一个构造器。

如果需要,您也可以提供自己的例外情况class。