00001 #include <vector> 00002 using namespace std; 00003 00004 // car, all car elements(parts) together 00005 class Car 00006 { 00007 public: 00008 vector<CarElement*>& getElements() 00009 { 00010 return elements_; 00011 } 00012 Car() 00013 { 00014 // assume that neither push_back nor Wheel(const string&) may throw 00015 elements_.push_back( new Wheel("front left") ); 00016 elements_.push_back( new Wheel("front right") ); 00017 elements_.push_back( new Wheel("back left") ); 00018 elements_.push_back( new Wheel("back right") ); 00019 elements_.push_back( new Body() ); 00020 elements_.push_back( new Engine() ); 00021 } 00022 ~Car() 00023 { 00024 for(vector<CarElement*>::iterator it = elements_.begin(); 00025 it != elements_.end(); ++it) 00026 { 00027 delete *it; 00028 } 00029 } 00030 private: 00031 vector<CarElement*> elements_; 00032 }; 00033