#include <iostream> using namespace std; class Person { public: virtual void Show() = 0; }; class Girl:public Person { public: void Show() { cout << "I am a girl!" << endl; } }; class Clothes:public Person { public: Person* tperson; void Decorator(Person* person) { tperson = person; } virtual void Show() { tperson->Show(); } }; class Dress:public Clothes { public: void Show() { Clothes::Show(); cout << "穿连衣裙" << endl; } }; class Skirt:public Clothes { public: void Show() { Clothes::Show(); cout << "穿短裙子" << endl; } }; class Trousers:public Clothes { public: void Show() { Clothes::Show(); cout << "穿裤子" << endl; } }; class TShirts:public Clothes { public: void Show() { Clothes::Show(); cout << "穿T桖" << endl; } }; class Shoes:public Clothes { public: void Show() { Clothes::Show(); cout << "穿鞋子" << endl; } }; int main() { Girl* girl = new Girl; cout << "第一种装扮:" << endl; Dress* dress = new Dress; dress->Decorator(girl); Shoes* shoes = new Shoes; shoes->Decorator(dress); shoes->Show(); delete dress; delete shoes; cout << endl << "第二种装扮:" << endl; TShirts* tShirt = new TShirts; tShirt->Decorator(girl); Skirt* skirt = new Skirt; skirt->Decorator(tShirt); shoes = new Shoes; shoes->Decorator(skirt); shoes->Show(); de lete skirt; delete tShirt; delete shoes; delete girl; return 0; }