1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#include <string> #include <vector> class Dog { private: std::string name; public: Dog(std::string name) : name(name) {} std::string speak() { return "woof"; } bool validate() { return name.length() > 0; } }; class Cat { private: std::string name; public: Cat(std::string name) : name(name) {} std::string speak() { return "meow"; } bool validate() { return name.length() > 0 && name.length() < 50; } }; class Shelter { private: std::vector<void*> animals; public: void add(void* animal) { animals.push_back(animal); } int count() { return animals.size(); } };