"no matching function for call to ‘async(std::launch, <unresolved overloaded function type>, std::string&)’"

Andres La picture Andres La · May 12, 2015 · Viewed 9.4k times · Source

I am trying to create a thread using std::async, but I keep getting the error "no matching function for call to ‘async(std::launch, <unresolved overloaded function type>, std::string&)’" on the line

ConnectFuture = std::async(std::launch::async, Connect_T,ip);

Here is the code that produces this behaviour:

#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;
}

Answer

Mike Seymour picture Mike Seymour · May 12, 2015

It's a member function, so it needs an object to be called on as well as an argument. Maybe it should be static, or maybe you should bind it to this:

std::async(std::launch::async, &libWrapper::Connect_T, this, ip)