do_rand_stf is a non-static member function and therefore cannot be called without an instance of the class (implicit this parameter). Fortunately, std::async processes its parameters, such as std::bind , and bind in turn can use std::mem_fn to turn a pointer to a member function into a functor that takes an explicit this parameter, so that's all what you need to do is pass this to the std::async call and use the syntax of the member syntax function pointer when passing do_rand_stf :
auto hand=async(launch::async,&A::do_rand_stf,this,i,j);
However, there are other problems in the code. First, you use
std::cout and
std::endl without
#include ing
<iostream> . More seriously,
std::future is not copyable, only movable, so you cannot
push_back named
hand object without using
std::move . Or just pass the
async result to
push_back directly:
ran.push_back(async(launch::async,&A::do_rand_stf,this,i,j));
JohannesD Aug 01 2018-12-12T00: 00Z
source share