Is it possible to call a function async and return a value with a class method:
void A::GetReply()
{
std::async([this](const struct mydata& msg)
{
oncall(msg);
}));
void A::onReply(const struct mydata& msg)
{
return msg.value;
}
I get compilation error:
6>: error C2672: 'std::async': no matching overloaded function found
6>: error C2893: Failed to specialize function template 'std::future<_Invoke_traits<void,_Callable,decay<_ArgTypes>::type...>::type> std::async(_Fty &&,_ArgTypes &&...)'
6> with
6> [
6> _Callable=decay<_Ty>::type
6> ]
6>: note: With the following template arguments:
6>: note: '_Fty=A::{ctor}::<lambda_75cbb6e549dc12613fd9546c1d31aa61>'
6>: note: '_ArgTypes={}'
6>: error C2780: 'std::future<_Invoke_traits<void,_Callable,decay<_ArgTypes>::type...>::type> std::async(std::launch,_Fty &&,_ArgTypes &&...)': expects 3 arguments - 1 provided
6> with
6> [
6> _Callable=decay<_Ty>::type
6> ]
6>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.15.26726\include\future(1821): note: see declaration of 'std::async'
What is correct way of implementation a function call for 'future' with launch as async and get the return value of the async function call?
Aucun commentaire:
Enregistrer un commentaire