我正在尝试使用std::async
创建一个线程,但我一直收到错误
“在行
async(std::launch, <unresolved overloaded function type>, std::string&)
'”没有匹配功能
ConnectFuture = std::async(std::launch::async, Connect_T,ip);
以下是产生此行为的代码:
#include <future>
class libWrapper
{
public:
void Connect(std::string ip);
void Connect_T(std::string ip);
private:
std::future<void> ConnectFuture;
};
void libWrapper::Connect(std::string ip){
auto status = ConnectFuture.wait_for(std::chrono::seconds(0));
if (status != std::future_status::timeout)
{
ConnectFuture = std::async(std::launch::async, Connect_T,ip);
}
}
void libWrapper::Connect_T(std::string ip)
{
}
int main(int argc, char** argv) {
libWrapper lW;
lW.Connect("192.168.3.1");
return 0;
}
答案 0 :(得分:6)
它是一个成员函数,因此需要调用一个对象以及一个参数。也许它应该是静态的,或者你应该将它绑定到this
:
std::async(std::launch::async, &libWrapper::Connect_T, this, ip)