MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / shear

Method shear

Exercises/Modules/Chapter 15/Soln15_05/Animals.cpp:56–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54}
55
56unsigned 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
72std::string_view Sheep::sound() const

Callers 1

mainFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected