我试图使用std::async
运行一个侦听器方法异步,但我得到了以下错误:No instance of overloaded function "std::async" matches argument list
auto listener = std::async(std::launch::async, server.Listen());
server.Listen()
返回void (nothing),我已经阅读过https://en.cppreference.com/w/cpp/thread/async
以供参考。
template< class Function, class... Args >
std::future<std::invoke_result_t<std::decay_t<Function>, std::decay_t<Args>...>>
async( std::launch policy, Function&& f, Args&&... args );
template< class Function, class... Args >
std::future<std::invoke_result_t<std::decay_t<Function>, std::decay_t<Args>...>>
async( std::launch policy, Function&& f, Args&&... args );
我将C++20与CMAKE结合使用。
完整的main.cpp
代码:
#include <iostream>
#include <future>
#include <string>
#include <stdio.h>
#include "../<redacted>/IPC/UnixSocket/Server.h"
// https: // github.com/MikeShah/moderncppconcurrency/blob/main/async_buffer.cpp
int main()
{
printf("Hello World from <redacted>.Demo.IPCServer!\n");
<redacted>::IPC::UnixSocket::Server server(1556, SOCK_STREAM, INADDR_ANY);
auto listener = std::async(std::launch::async, server.Listen());
return 0;
}
我还得到了所有std::async
或std::future
类型的intellisense问题:<error-type>
--我不知道这是否也是某种东西的指示器。
有人能帮忙吗?
https://stackoverflow.com/questions/74327997
复制相似问题