How can I pass an object to a function which is started asynchronously?
#include <future>
#include <thread>
class SomeObject
{
void Dummy();
}
class A
{
public:
void Test1();
void Test2(SomeObject o);
void Test3(SomeObject &o);
}
A a;
auto a = std::async(std::launch::async, &A::Test1, a); // OK
SomeObject o;
auto b = std::async(std::launch::async, &A::Test2, a, o); // ERROR
auto c = std::async(std::launch::async, &A::Test3, a, std::ref(o)); // ERROR
The function T1 is launched without error. The Test2 and Test3 need an object argument, but I get and error: No instance of overloaded function std::async matches the argument list.