dlib> #include “../purge.h” us

Автор admin Понедельник, 22 июня 2009 11:32

dlib> #include “../purge.h” using namespace std; class Paper; class Scissors; class Rock; enum Outcome { WIN. LOSE, DRAW }: ostream& operator«(ostream& os, const Outcome out) { switch(out) { default: case WIN: return os « “win”: case LOSE: return os « “lose”: case DRAW: return os « “draw”: } } class Item { public: virtual Outcome compete(const Item*) = 0; virtual Outcome eval(const Paper*) const = 0; virtual Outcome eval(const Scissors*) const= 0; virtual Outcome eval(const Rock*) const = 0: virtual ostream& print(ostream& os) const = 0: virtual -ItemO {} friend ostream& operator«(ostream& os. const Item* it) { Рассматривается в книге БЧ при описании эталона Посетитель, о котором речь далее в этом разделе. Множественная диспетчеризация и паттерн Посетитель 523 return it->print(os); } }: class Paper : public Item { public: Outcome compete(const Item* it) { return it->eval(this):} Outcome eval(const Paper*) const { return DRAW; } Outcome eval(const Scissors*) const { return WIN; } Outcome eval(const Rock*) const { return LOSE: } ostream& print(ostream& os) const { return os « “Paper “; } }: class Scis


Комментарии закрыты.