title: Destructor is not called in Factory Pattern
body: <p>I am learning factory design pattern and this is how I have implemented in C++. CVehicle is abstract class having interface <em>createVehical</em> to create actual object of specific type. CVehicalBookingHandler  is client code which will be exposed and needs not to be modified, it will also delete actual vehicle object in it's destructor. But when its destructor is called to delete actual objects, their destructors are not called. How can I fix it??</p>
  
  <pre><code>
  #include&lt;iostream&gt;
  
  using namespace std;
  
  enum EVehicleType{
      VT_Bus, VT_Train, VT_Flight 
  };
  
  class CVehical{
  public:
      virtual bool Book()=0;
      static CVehical* createVehical(EVehicleType vehicleType);
  };
  
  class CBus:public CVehical{
  public:
      bool Book(){
          cout&lt;&lt;"Bus is booked!"&lt;&lt;endl;
          return true;
      }
      ~CBus(){
          cout&lt;&lt;"CBus deleted"&lt;&lt;endl;
      }
  };
  
  class CTrain:public CVehical{
  public:
      bool Book(){
          cout&lt;&lt;"Train is booked!"&lt;&lt;endl;
          return true;
      }
      ~CTrain(){
          cout&lt;&lt;"Train deleted"&lt;&lt;endl;
      }
  };
  
  class CFlight:public CVehical{
  public:
      bool Book(){
          cout&lt;&lt;"Flight is booked!"&lt;&lt;endl;
          return true;
      }
      ~CFlight(){
          cout&lt;&lt;"Flight deleted"&lt;&lt;endl;
      }
  };
  
  CVehical* CVehical::createVehical(EVehicleType vehicleType){
  
      if(VT_Bus == vehicleType){
          return new CBus();
      }
      else if(VT_Train == vehicleType){
          return new CTrain();
      }
      else if(VT_Flight == vehicleType){
          return new CFlight();
      }
      else{
          return NULL;
      }
  }
  
  
  class CVehicalBookingHandler{
  private:
      CVehical* vehicle;
      EVehicleType eVehicleType;
  
  public:
      CVehicalBookingHandler(EVehicleType eVehicleType):eVehicleType(eVehicleType){
          vehicle=CVehical::createVehical(eVehicleType);
      }
      ~CVehicalBookingHandler(){
          if(vehicle){
              delete vehicle;
              vehicle=NULL  ;
          }
      }
      CVehical* getVehicle(){
          return vehicle;
      }
  
      EVehicleType getVehicleType(){
          return eVehicleType;
      }
  };
  
  
  int main(){
      CVehicalBookingHandler busBookingHandler(VT_Bus);
      CVehical* vehicle=busBookingHandler.getVehicle();
      vehicle-&gt;Book();
  
      CVehicalBookingHandler trainBookingHandler(VT_Train);
      vehicle=trainBookingHandler.getVehicle();
      vehicle-&gt;Book();
  
      CVehicalBookingHandler flightBookingHandler(VT_Flight);
      vehicle=flightBookingHandler.getVehicle();
      vehicle-&gt;Book();
  }
  </code></pre>
  
  <p><strong>output:</strong></p>
  
  <p>Bus is booked!</p>
  
  <p>Train is booked!</p>
  
  <p>Flight is booked!</p>