adding the unique function line
This commit is contained in:
committed by
JamesFlare1212
parent
45124db960
commit
284bd60029
@@ -344,7 +344,7 @@ int main() {
|
||||
|
||||
## 27.15 Exercise
|
||||
|
||||
In the following program, the use count will be printed 3 times. What exact value will be printed each time?
|
||||
In the following [program](shared_ptr1.cpp), the use count will be printed 3 times. What exact value will be printed each time?
|
||||
|
||||
```cpp
|
||||
#include <iostream>
|
||||
@@ -364,6 +364,10 @@ int main(){
|
||||
}
|
||||
std::cout << "the use count is : " << age.use_count() << std::endl;
|
||||
|
||||
if(age.unique()){
|
||||
std::cout << "Congratulations! I am yours!" << std::endl;
|
||||
}
|
||||
|
||||
// give up my ownership, it decreases the reference count of the managed object by one.
|
||||
// if that shared pointer was the last owner (i.e., reference count becomes zero), the object is deleted.
|
||||
// the shared_ptr itself is now empty (i.e., it holds nullptr).
|
||||
|
||||
@@ -15,6 +15,10 @@ int main(){
|
||||
}
|
||||
std::cout << "the use count is : " << age.use_count() << std::endl;
|
||||
|
||||
if(age.unique()){
|
||||
std::cout << "Congratulations! I am yours!" << std::endl;
|
||||
}
|
||||
|
||||
// give up my ownership, it decreases the reference count of the managed object by one.
|
||||
// if that shared pointer was the last owner (i.e., reference count becomes zero), the object is deleted.
|
||||
// the shared_ptr itself is now empty (i.e., it holds nullptr).
|
||||
|
||||
Reference in New Issue
Block a user