Skip to content

Instantly share code, notes, and snippets.

@JohnCoconut
Created June 28, 2018 14:14
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 JohnCoconut/3f77f5b4ea4a2e1b58354225180e5c30 to your computer and use it in GitHub Desktop.
Save JohnCoconut/3f77f5b4ea4a2e1b58354225180e5c30 to your computer and use it in GitHub Desktop.
// Create a unique pointer
auto p1 = std::make_unique<int>(42);
// Error to copy
auto p2 = p1;
// Ok to move
auto p2 = std::move(p1);
// After being moved, p1 is guaranted be equal to nullptr
assert(p1 == nullptr);
// It's a runtime error to access p1
int x = *p1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment