c++ No instance of overloaded function "std::async" matches argument list

449 Views Asked by At

i'm trying to run a listener Method async with std::async but i get the following error: No instance of overloaded function "std::async" matches argument list

auto listener = std::async(std::launch::async, server.Listen());

The server.Listen() returns void (nothing) I've already read throu https://en.cppreference.com/w/cpp/thread/async for reference.

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 );

I'm using C++20 with CMAKE.

The full main.cpp Code:

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

i also get an intellisense issue on all the std::async or std::future types: <error-type> - i don't know if this might also be an indicator for something.

Can someone help?

1

There are 1 best solutions below

0
On BEST ANSWER

Solution

thanks y'all for your answers, both solutions worked!
and also thanks for the comment on the <redacted> 'practice'

the working code:

auto listener = std::async(
    std::launch::async, 
    &myprojectlibrary::IPC::UnixSocket::Server::Listen, 
    std::ref(server)
);
auto listener = std::async(
    std::launch::async, 
    [&]{ server.Listen(); }
);