Skip to content

Commit

Permalink
added section 15.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
pezy committed Jun 15, 2015
1 parent 2e82975 commit 820a141
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 85 deletions.
18 changes: 18 additions & 0 deletions ch15/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,21 @@ Different from previous program, it can be found that 20% and 50% discount has b
- (a): `WordQuery` -> `NotQuery` -> `AndQuery` -> `OrQuery`
- (b): `WordQuery` -> `NotQuery` -> `AndQuery` -> `OrQuery` (same as the previous one)
- (c): `WordQuery` -> `AndQuery` -> `OrQuery`

## Exercise 15.32:
> What happens when an object of type `Query` is copied, moved, assigned, and destroyed?
- **copy**: While being copied, the synthesized copy constructor is called. It copies the data member into the new object. Since in this case, the data member is a shared pointer, while copying, the corresponding shared pointer points to the same address and the use count from the both shared pointer becomes 2.

- **move**: while being moved, the synthesized move constructor is called. It moves the data member into the new object. In this case, the shared pointer from the newly created object will point to the address to which the original shared pointer pointed. After the move operation, the use count of the shared pointer in the new object is 1, whereas the pointer from the original object becomes `nullptr`.

- **copy assignment**: The synthesized copy assignment will be called. The outcome of this operation is identical with the copy operation.

- **move assignment**: The synthesized move assignment will be called. The rest is the same as the move operation.

- **destroy**: The synthesized destructor will be called. It will call the destructor of `shared_ptr` which decrements the use count. If the count becomes zero, the destructor from `shared_ptr` will delete the resources it point to.

## Exercise 15.33:
> What about objects of type `Query_base`?
Managed by the synthesized version. Since `Query_base` a abstract class, the object of this type is essentially a sub-object of its derived class.
85 changes: 0 additions & 85 deletions ch15/ex15.31.32.33.cpp

This file was deleted.

0 comments on commit 820a141

Please sign in to comment.