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
| class Dog : public Animal { public: Dog() {} ~Dog() override {}
Animal *clone() override { Dog *dog = new Dog(); strncpy(dog->m_name, m_name, 32); return dog; } void play() override { }
private: char m_name[32]; };
class Cat : public Animal { public: Cat() {} ~Cat() override {}
Animal *clone() override { Cat *cat = new Cat(); strncpy(cat->m_name, m_name, 32); return cat; } void play() override { }
private: char m_name[32]; };
|