首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >c++没有重载函数“std::异步”的实例匹配参数列表

c++没有重载函数“std::异步”的实例匹配参数列表
EN

Stack Overflow用户
提问于 2022-11-05 13:12:40
回答 1查看 91关注 0票数 0

我试图使用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以供参考。

代码语言:javascript
运行
复制
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代码:

代码语言:javascript
运行
复制
#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::asyncstd::future类型的intellisense问题:<error-type> --我不知道这是否也是某种东西的指示器。

有人能帮忙吗?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74327997

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档