mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-18 02:24:35 +03:00
2
CPP11.md
2
CPP11.md
@@ -559,7 +559,7 @@ Transferring `std::unique_ptr`s:
|
|||||||
```c++
|
```c++
|
||||||
std::unique_ptr<int> p1{ new int };
|
std::unique_ptr<int> p1{ new int };
|
||||||
std::unique_ptr<int> p2 = p1; // error -- cannot copy unique pointers
|
std::unique_ptr<int> p2 = p1; // error -- cannot copy unique pointers
|
||||||
std::unique_ptr<int> p3 = std::move(p1); // move `p1` into `p2`
|
std::unique_ptr<int> p3 = std::move(p1); // move `p1` into `p3`
|
||||||
// now unsafe to dereference object held by `p1`
|
// now unsafe to dereference object held by `p1`
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -1151,7 +1151,7 @@ Transferring `std::unique_ptr`s:
|
|||||||
```c++
|
```c++
|
||||||
std::unique_ptr<int> p1{ new int };
|
std::unique_ptr<int> p1{ new int };
|
||||||
std::unique_ptr<int> p2 = p1; // error -- cannot copy unique pointers
|
std::unique_ptr<int> p2 = p1; // error -- cannot copy unique pointers
|
||||||
std::unique_ptr<int> p3 = std::move(p1); // move `p1` into `p2`
|
std::unique_ptr<int> p3 = std::move(p1); // move `p1` into `p3`
|
||||||
// now unsafe to dereference object held by `p1`
|
// now unsafe to dereference object held by `p1`
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user