Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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;
}
like image 630
Andres La Avatar asked May 12 '15 15:05

Andres La


1 Answers

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)
like image 96
Mike Seymour Avatar answered Oct 02 '22 00:10

Mike Seymour