Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用参数C+;调用std::thread函数时出现编译器错误+;_C++_Stdthread - Fatal编程技术网

C++ 使用参数C+;调用std::thread函数时出现编译器错误+;

C++ 使用参数C+;调用std::thread函数时出现编译器错误+;,c++,stdthread,C++,Stdthread,我试图从一个新线程调用一个函数。该函数接受一组参数 std::thread signingThread(curlWrapper->SendDataToServer,username, password, serverURL, data); 下面是函数原型 int LibCurlWrapper::SendDataToServer(const std::string& username, const std::string& password, const std::stri

我试图从一个新线程调用一个函数。该函数接受一组参数

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)
int LibCurlWrapper::SendDataToServer(const std::string&username,const std::string&password,const std::string&serverURL,const std::vector&vData)
编译器错误

错误:调用“std::thread::thread(,std::string&,std::string&,std::string&,std::string&,std::vector&)”时没有匹配的函数 std::线程签名读取(curlWrapper->SendDataToServer、用户名、密码、服务器URL、数据)


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

将其更改为:

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

<代码> CURLWRAPPER > SDEDATATOSRVER < /COD>是无稽之谈,这不是有效的C++。关于启动
std::thread
以运行成员函数,StackOverflow上有数百个问题。LibCurlWrapper*curlWrapper=new LibCurlWrapper;“为什么这是胡说八道?”乔纳森·韦克利说,在发布这篇文章之前,我搜索了很多……但我所看到或读到的东西都没有用。如果你有一个链接,请分享。Thnx因为您不能引用这样的成员函数。如果您在函数调用中使用参数列表,则可以在函数调用中使用
curlWrapper->SendDataToServer
,但您没有这样做。您需要使用指向成员函数的指针和指向调用该函数的对象的指针/引用来构造线程。这里有一个现有问题的例子:当我尝试你建议的方法时,我得到了以下编译器错误。错误:typedef typename result\u of::type result\u type的“class std::result\u”中没有名为“type”的类型^@nateN你在用什么编译器?我试过叮当声,它编译得很好。(虽然得到了一个链接错误。)啊…错过了一个细节…忘记添加第二个参数。现在它工作了!感谢you@nateN很高兴能帮上忙!如果您觉得它对您有用,请随时使用。:-)