00001 #include <iostream>
00002 using namespace std;
00003
00004 class CarElementDoVisitor : public CarElementVisitor
00005 {
00006 public:
00007
00008 void visit(Wheel& wheel) const
00009 {
00010 cout << "Kicking my " << wheel.getName() << " wheel" << endl;
00011 }
00012 void visit(Engine& engine) const
00013 {
00014 cout << "Starting my engine" << endl;
00015 }
00016 void visit(Body& body) const
00017 {
00018 cout << "Moving my body" << endl;
00019 }
00020 void visitCar(Car& car) const
00021 {
00022 cout << endl << "Starting my car" << endl;
00023 vector<CarElement*>& elems = car.getElements();
00024 for(vector<CarElement*>::iterator it = elems.begin();
00025 it != elems.end(); ++it )
00026 {
00027 (*it)->accept(*this);
00028 }
00029 cout << "Stopped car" << endl;
00030 }
00031 };
00032