mercredi 29 juin 2016

Using a std::promise with thread with member function error C2664

I am getting an error saying

error C2664: 'void std::_Pmf_wrap> &&),void,WalkingController,std::promise> &&>::operator ()(_Farg0 &,std::promise> &&) const' : cannot convert argument 2 from 'std::promise>' to 'std::promise> &&'

I am trying to create a promise that will run on a separate thread to execute a member function in my class. It looks like this:

std::promise<std::tuple<float, float>> p_upperTorques;
auto f_upperTorques = p_upperTorques.get_future();
std::thread t1(&WalkingController::CalculateTorqueForUpperLegs, this, std::move(p_upperTorques));
t1.join();
...std::get<0>(f_upperTorques.get()), std::get<1(f_upperTorques.get())...

The function I am calling is

void WalkingController::CalculateTorqueForUpperLegs(std::promise<std::tuple<float, float>> &&p) {
...
p.set_value(std::make_tuple(ullTorque, urlTorque));
}

Whats the correct way to do this?

Thanks for the help.

Aucun commentaire:

Enregistrer un commentaire