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

Method herd

Exercises/NoModules/Chapter 15/Soln15_05/Zoo.cpp:27–39  ·  view source on GitHub ↗

Collect all Sheep in the Zoo using dynamic cast (the recommended way)

Source from the content-addressed store, hash-verified

25
26// Collect all Sheep in the Zoo using dynamic cast (the recommended way)
27std::vector<SheepPtr> Zoo::herd() const
28{
29 std::vector<SheepPtr> sheep;
30 for (auto animal : m_animals)
31 {
32 auto casted{ std::dynamic_pointer_cast<Sheep>(animal) };
33 if (casted)
34 {
35 sheep.push_back(casted);
36 }
37 }
38 return sheep;
39}

Callers 1

mainFunction · 0.45

Calls 1

push_backMethod · 0.45

Tested by

no test coverage detected