mardi 22 septembre 2015

How to move unique_ptr if you have only *ptr

How to release ownership from uPtr if you have only pointer to the managed object. Is that possible?

int main()
{
   unique_ptr<int> uPtr (new int(5));
   int* ptr;

   ptr = uPtr.get();
   //I dont want to do ptr = uPtr.release()

   unique_ptr<int> newUPtr;

   //here how to move uPtr to newUPtr using only ptr;
   newUPtr = ???ptr;
}

This is simple example, which shows want I want to do. I could do `newUPtr = move(uPtr)', but I had to find unique_ptr in vector to object having only *ptr, and it would be more complicated.

Aucun commentaire:

Enregistrer un commentaire