Advertisement
Guest User

Untitled

a guest
Apr 28th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. std::unique_ptr<int> p1(new int(5));
  2. std::unique_ptr<int> p2 = p1; //Compile error.
  3. std::unique_ptr<int> p3(new int(6));
  4.  
  5. std::unique_ptr<int> p3 = std::move(p1); //Transfers ownership. p3 now owns the memory and p1 is rendered invalid.
  6. p3.reset(); //Deletes the memory.
  7. p1.reset(); //Does nothing.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement