Skip to content

Instantly share code, notes, and snippets.

@RklAlx
Created September 27, 2013 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RklAlx/6727554 to your computer and use it in GitHub Desktop.
Save RklAlx/6727554 to your computer and use it in GitHub Desktop.
std::unique_ptr
std::unique_ptr<int> p1(new int(5));
std::unique_ptr<int> p2 = p1; //Compile error.
std::unique_ptr<int> p3 = std::move(p1); //Transfers ownership. p3 now owns the memory and p1 is rendered invalid.
p3.reset(); //Deletes the memory.
p1.reset(); //Does nothing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment