-1

I'm trying to get my head around async but have not yet found a way to pass pointers. The aim is to pass a pointer to a pointer so that the thread readTable initialises the pointer to a PostgreSQL connection as shown below.

PGconn *conn = NULL;
future<int> resultFuture;

void init
{
    resultFuture = async(launch::async, readTable(&conn));
}

However the compiler complains with:
error: no matching function for call to ‘async(std::launch, int)'

Is passing pointers like this not allowed with async?

Thanks for any help.

Smithy
  • 1,157
  • 3
  • 11
  • 18

1 Answers1

0

I guess

void init
{
    resultFuture = async(launch::async, readTable,&conn);
}

the second parameters is a Callable (which is a function to pointer, or an object with overloaded operator() or a lambda function). all the rest are the argument to pass into the callable.

please read std::async documentation here: http://en.cppreference.com/w/cpp/thread/async

and about perfect forwarding here : Advantages of using forward

Community
  • 1
  • 1
David Haim
  • 25,446
  • 3
  • 44
  • 78