#include<iostream> using namespace std; class Smoothy{ private: int price; public: int getPrice(){ return price; } virtual ~Smoothy() = default; virtual string description() = 0; }; class BasicSmoothy: public Smoothy{ private: string nume; public: BasicSmoothy(string n): nume(n){} string description(){ return nume; } }; class SmoothyDecorator:public Smoothy{ private: Smoothy *b; public: SmoothyDecorator(Smoothy* bb){ b = bb; } ~SmoothyDecorator(){ delete b; } string description(){ return b->description(); } }; class SmoothyWithCream:public SmoothyDecorator{ public: SmoothyWithCream(Smoothy *b):SmoothyDecorator(b){ } string description(){ return SmoothyDecorator::description() + " with Cream!"; } }; class SmoothyWithCinnamon:public SmoothyDecorator{ public: SmoothyWithCinnamon(Smoothy *b):SmoothyDecorator(b){ } string description(){ return SmoothyDecorator::description() + " with Cinnamon!"; } }; int main(){ Smoothy* b = new SmoothyWithCinnamon(new BasicSmoothy("Kiwi")); cout<<b->description(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)