mardi 5 mars 2019

Moving a value of object to another but avoid copying

There is a scenario where when I get a reply from an API via a callback and I need to move the objects in reply to my class member variable to proceed processing. Will the following code achieve the objective:

class A
{
public:
 A(Obj& r) {}
};

void A::GetResponse(Obj&& resp)
{
  //pvtmemVarTyOfObj = std::forward<Obj>(std::move(resp));
   pvtmemVarTyOfObj = std::move(resp);

}

Will this code actually move resp to pvtmemVarTyOfObj member variable? Just to ensure that no-copy should be done as it will lead to huge processing cost?

Aucun commentaire:

Enregistrer un commentaire