当前位置: 代码迷 >> 综合 >> C++ no matching function for call to ‘async‘
  详细解决方案

C++ no matching function for call to ‘async‘

热度:87   发布时间:2024-01-10 02:45:56.0

原文链接:c++ - "no matching function for call to ‘async(std::launch, <unresolved overloaded function type>, std::string&)’" - Stack Overflow

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

2种方式解决这个问题:

第一种:

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

第二种:用static

 static std::string Connect_T(std::string ip);

 然后我在omnet++里应该是编译器的原因clang++,如果函数Connect_T的入参是引用,得在参数前显示声明成引用

std::async(std::launch::async,Connect_T,std::ref(str));

  相关解决方案