// 比如穿T恤,衬衫,外套,皮鞋,运动鞋,靴子...,根据下面的类图完
//被装饰的类
class Person
{
public:
string m_name;
Person() {}; //子类实例化需要无参构造
Person(string name) :m_name(name) {}
virtual void show() { cout << m_name; };
};
//装饰器父类 抽象类
class Finery:public Person
{
protected:
Person* m_per;
public:
Finery(Person* p) :m_per(p) {}; //这里使用person类无参构造 先父类无参 再子类构造
//Finery(Person name, Person* perman) :Person(name), m_per(perman) {}
virtual void show() =0;
};
//具体装饰类
class LongTrouser :public Finery
{
public:
LongTrouser(Person* p):Finery(p) {}; //显示构造父类
void show() {
//调用原来的showf方法
m_per->show();
//装饰
cout << "长袜" << endl;
}
};
class Tshiirts :public Finery