22.C++设计模式之装饰者模式

#define  _CRT_SECURE_NO_WARNINGS
#include 
using namespace std;


class Car {
public:
    virtual void go() = 0;
};

class RunCar :public Car {
public:
    virtual void go() {
        cout<<"汽车跑"<m_car = car;
    }

    virtual void go() {
        m_car->go();
        cout << "汽车飞" << endl;
    }
};

void main() {
    Car* car = new RunCar();
    Car* car2 = new CarDecoration(car);
    car2->go();
    delete car2;
    delete car;
    system("pause");
}

你可能感兴趣的:(22.C++设计模式之装饰者模式)