mirror of
https://github.com/changkun/modern-cpp-tutorial.git
synced 2025-12-16 20:27:08 +03:00
book: add line breaks for code formatting (#226)
This commit is contained in:
@@ -58,20 +58,26 @@ auto pointer = std::make_shared<int>(10);
|
||||
auto pointer2 = pointer; // reference count+1
|
||||
auto pointer3 = pointer; // reference count+1
|
||||
int *p = pointer.get(); // no increase of reference count
|
||||
|
||||
std::cout << "pointer.use_count() = " << pointer.use_count() << std::endl; // 3
|
||||
std::cout << "pointer2.use_count() = " << pointer2.use_count() << std::endl; // 3
|
||||
std::cout << "pointer3.use_count() = " << pointer3.use_count() << std::endl; // 3
|
||||
|
||||
pointer2.reset();
|
||||
std::cout << "reset pointer2:" << std::endl;
|
||||
|
||||
std::cout << "pointer.use_count() = " << pointer.use_count() << std::endl; // 2
|
||||
std::cout << "pointer2.use_count() = " << pointer2.use_count() << std::endl; // 0, pointer2 has reset
|
||||
std::cout << "pointer2.use_count() = "
|
||||
<< pointer2.use_count() << std::endl; // 0, pointer2 has reset
|
||||
std::cout << "pointer3.use_count() = " << pointer3.use_count() << std::endl; // 2
|
||||
|
||||
pointer3.reset();
|
||||
std::cout << "reset pointer3:" << std::endl;
|
||||
|
||||
std::cout << "pointer.use_count() = " << pointer.use_count() << std::endl; // 1
|
||||
std::cout << "pointer2.use_count() = " << pointer2.use_count() << std::endl; // 0
|
||||
std::cout << "pointer3.use_count() = " << pointer3.use_count() << std::endl; // 0, pointer3 has reset
|
||||
std::cout << "pointer3.use_count() = "
|
||||
<< pointer3.use_count() << std::endl; // 0, pointer3 has reset
|
||||
```
|
||||
|
||||
## 5.3 `std::unique_ptr`
|
||||
|
||||
Reference in New Issue
Block a user