Skip to content

Commit

Permalink
added 13.22 ~ 26
Browse files Browse the repository at this point in the history
  • Loading branch information
pezy committed Jan 19, 2015
1 parent ad9cd41 commit e0ec0d2
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 377 deletions.
21 changes: 21 additions & 0 deletions ch13/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,24 @@ TextQuery& operator=(const TextQuery) = delete;
QueryResult(const QueryResult&) = delete;
QueryResult& operator=(const QueryResult) = delete;
```
## [Exercise 13.22](ex13_22.h)
## Exercise 13.23:
>Compare the copy-control members that you wrote for the solutions to the previous section’s exercises to the code presented here. Be sure you understand the differences, if any, between your code and ours.
Check 13.22.
## Exercise 13.24:
>What would happen if the version of HasPtr in this section didn’t define a destructor? What if HasPtr didn’t define the copy constructor?
If `HasPtr` didn't define a destructor, memory leak will happened. If `HasPtr` didn't define the copy constructor, when assignment happened, just points copied, the string witch `ps` points haven't been copied.
## Exercise 13.25:
>Assume we want to define a version of StrBlob that acts like a value. Also assume that we want to continue to use a shared_ptr so that our StrBlobPtr class can still use a weak_ptr to the vector. Your revised class will need a copy constructor and copy-assignment operator but will not need a destructor. Explain what the copy constructor and copyassignment operators must do. Explain why the class does not need a destructor.
Copy constructor and copy-assignment operator should dynamicly allocate memory for its own , rather than share the object with the right hand operand.
`StrBlob` is using smart pointers which can be managed with synthesized destructor, If an object of `StrBlob` is out of scope, the destructor for std::shared_ptr will be called automaticaly to free the memory dynamically allocated when the `use_count` goes to 0.
## Exercise 13.26 [hpp](ex13_26.h) | [cpp](ex13_26.cpp)
89 changes: 0 additions & 89 deletions ch13/ex13.20.21.22.cpp

This file was deleted.

199 changes: 0 additions & 199 deletions ch13/ex13.25.26/StrBlob.h

This file was deleted.

83 changes: 0 additions & 83 deletions ch13/ex13.25.26/main.cpp

This file was deleted.

Loading

0 comments on commit e0ec0d2

Please sign in to comment.