| 54 | } |
| 55 | |
| 56 | unsigned Sheep::shear() |
| 57 | { |
| 58 | // Somewhat odd statement that updates the total weight (stored in the Animal subobject) |
| 59 | // to the actual weight of the sheep (see Sheep::getWeight()). |
| 60 | // Of course, we do this *before* setting the wool's weight to 0. |
| 61 | setWeight(getWeight()); |
| 62 | |
| 63 | const unsigned wool_weight{ m_wool_weight }; |
| 64 | m_wool_weight = 0; |
| 65 | return wool_weight; |
| 66 | |
| 67 | // Alternative: use std::exchange() (see Exercise 18-5) |
| 68 | //return std::exchange(m_wool_weight, 0); |
| 69 | } |
| 70 | |
| 71 | // Make like a sheep |
| 72 | std::string_view Sheep::sound() const |