Created
June 28, 2018 14:14
-
-
Save JohnCoconut/3f77f5b4ea4a2e1b58354225180e5c30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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