调用带有形参的std::thread函数时的编译器错误

compiler error when calling a std::thread function with parameters C++

本文关键字:函数 错误 编译器 thread std 形参 调用      更新时间:2023-10-16

我正在尝试从一个新线程调用一个函数。该函数接受一组形参。

std::thread signingThread(curlWrapper->SendDataToServer,username, password, serverURL, data);

这是函数原型

int LibCurlWrapper::SendDataToServer(const std::string& username, const std::string& password, const std::string& serverURL, const std::vector<unsigned char> &vData)

编译错误

错误:调用std::thread::thread(, std::string&, std::string&, std::string&, std::string&, std::vector&)没有匹配的函数std::thread signingThread(curlWrapper->SendDataToServer,username, password, serverURL, data);

您需要为std::thread指定一个函数,而curlWrapper->SendDataToServer没有也不能指定。(虽然curlWrapper->SendDataToServer()表示在curlWrapper上调用SendDataToServer())

改为:

std::thread signingThread(&LibCurlWrapper::SendDataToServer, curlWrapper, username, password, serverURL, data);