class Vehicle { public: virtual double weight() const=0; virtual void start()=0; virtual Vehicle* copy() const=0; virtual ~Vehicle(){} }; class RoadVehicle:public Vehicle {}; class AutoVehicle:public Vehicle {}; class Aircraft:public Vehicle {}; class Helicopter:public Vehicle {}; class Truck:public Vehicle { Vehicle* copy() const; double weight() const{return 1.0;} void start(){} }; Vehicle* Truck::copy() const { return new Truck(*this); } class VehicleSurrogate { public: VehicleSurrogate(); VehicleSurrogate(const Vehicle&); VehicleSurrogate(const VehicleSurrogate&); ~VehicleSurrogate(); VehicleSurrogate& operator=(const VehicleSurrogate&); double weight() const; void start(); private: Vehicle* vp; }; VehicleSurrogate::VehicleSurrogate() :vp(NULL){} VehicleSurrogate::VehicleSurrogate(const Vehicle& v): vp(v.copy()){} VehicleSurrogate::VehicleSurrogate(const VehicleSurrogate& v): vp(v.vp?v.vp:NULL){} VehicleSurrogate& VehicleSurrogate::operator =(const VehicleSurrogate& v) { if(this!=&v) { delete vp; vp=v.vp?v.vp->copy():NULL; } return *this; } double VehicleSurrogate::weight() const { if(vp==NULL) throw "empty VehicleSurrogate.weight()"; return vp->weight(); } void VehicleSurrogate::start() { if(vp==NULL) throw "empty VehicleSurrogate.start()"; vp->start(); } VehicleSurrogate::~VehicleSurrogate() { delete vp; } int main() { VehicleSurrogate parking_lot[1000]; Truck x; parking_lot[0]=VehicleSurrogate(x); cout<<sizeof(parking_lot); return 0; }