"没有匹配函数来调用'async(std :: launch,<unresolved overloaded function type>,std :: string&)'"

And*_* La 4 c++ c++11 stdasync

我正在尝试创建一个线程使用std::async,但我不断收到错误"没有匹配函数来调用' async(std::launch, <unresolved overloaded function type>, std::string&)''就行了

ConnectFuture = std::async(std::launch::async, Connect_T,ip);
Run Code Online (Sandbox Code Playgroud)

以下是产生此行为的代码:

#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;
}
Run Code Online (Sandbox Code Playgroud)

Mik*_*our 9

它是一个成员函数,因此它需要一个对象被调用以及一个参数.也许它应该是静态的,或者你应该将它绑定到this:

std::async(std::launch::async, &libWrapper::Connect_T, this, ip)
Run Code Online (Sandbox Code Playgroud)