title: How can I call destructor for only derived class?
body: <p>I have two class Base and Derived. When I made only a Derived object in main and write return 0, I saw that , Destructor of base class and destructor of derived class are both called.</p>
  
  <p>Thus I made an error. The base class destructor work for deleting memory which has been already deleting by derived class destructor.</p>
  
  <p>So , I don't want to call destructor of base class. I want only call derived class destructor because I made only derived class object.</p>
  
  <p>This is my code and my error.</p>
  
  <pre><code>#include &lt;new&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  class Base {
  public:
      Base(){
          size=4;
          arr= new int[size];
          for(int i=0;i&lt;size;i++){
              arr[i]=0;
          }
      }
      ~Base(){
           cout&lt;&lt;"Base class destructor called"&lt;&lt;endl;
           delete[] arr;
      }
  protected:
      int *arr;
      int size;
  };
  
  class Derived : public Base {
  public:
      Derived(){
          size=5;
          arr= new int[size];
          for(int i=0;i&lt;size;i++){
              arr[i]=0;
          }
      }
      ~Derived(){
          cout&lt;&lt;"Derived class destructor called"&lt;&lt;endl;
          delete[] arr;
      }
  
  };
  
  int main(){
      Derived derivedObject;
      return 0;
  }
  </code></pre>
  
  <p>My error is that,</p>
  
  <pre><code>Derived class destructor called
  Base class destructor called
  *** Error in `./exe': double free or corruption (fasttop): 0x0000000001f20c40 ***
  ======= Backtrace: =========
  /lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f2d65d147e5]
  /lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7f2d65d1d37a]
  /lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7f2d65d2153c]
  ./exe[0x400c31]
  ./exe[0x400d31]
  ./exe[0x400afb]
  /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f2d65cbd830]
  ./exe[0x4009f9]
  ======= Memory map: ========
  00400000-00402000 r-xp 00000000 08:06 1183568                            /home/burhan/Desktop/hw5-1/exe
  00601000-00602000 r--p 00001000 08:06 1183568                            /home/burhan/Desktop/hw5-1/exe
  00602000-00603000 rw-p 00002000 08:06 1183568                            /home/burhan/Desktop/hw5-1/exe
  01f0f000-01f41000 rw-p 00000000 00:00 0                                  [heap]
  7f2d60000000-7f2d60021000 rw-p 00000000 00:00 0 
  7f2d60021000-7f2d64000000 ---p 00000000 00:00 0 
  7f2d65994000-7f2d65a9c000 r-xp 00000000 08:06 2110523                    /lib/x86_64-linux-gnu/libm-2.23.so
  7f2d65a9c000-7f2d65c9b000 ---p 00108000 08:06 2110523                    /lib/x86_64-linux-gnu/libm-2.23.so
  7f2d65c9b000-7f2d65c9c000 r--p 00107000 08:06 2110523                    /lib/x86_64-linux-gnu/libm-2.23.so
  7f2d65c9c000-7f2d65c9d000 rw-p 00108000 08:06 2110523                    /lib/x86_64-linux-gnu/libm-2.23.so
  7f2d65c9d000-7f2d65e5d000 r-xp 00000000 08:06 2110528                    /lib/x86_64-linux-gnu/libc-2.23.so
  7f2d65e5d000-7f2d6605d000 ---p 001c0000 08:06 2110528                    /lib/x86_64-linux-gnu/libc-2.23.so
  7f2d6605d000-7f2d66061000 r--p 001c0000 08:06 2110528                    /lib/x86_64-linux-gnu/libc-2.23.so
  7f2d66061000-7f2d66063000 rw-p 001c4000 08:06 2110528                    /lib/x86_64-linux-gnu/libc-2.23.so
  7f2d66063000-7f2d66067000 rw-p 00000000 00:00 0 
  7f2d66067000-7f2d6607d000 r-xp 00000000 08:06 2102075                    /lib/x86_64-linux-gnu/libgcc_s.so.1
  7f2d6607d000-7f2d6627c000 ---p 00016000 08:06 2102075                    /lib/x86_64-linux-gnu/libgcc_s.so.1
  7f2d6627c000-7f2d6627d000 rw-p 00015000 08:06 2102075                    /lib/x86_64-linux-gnu/libgcc_s.so.1
  7f2d6627d000-7f2d663ef000 r-xp 00000000 08:06 1966485                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
  7f2d663ef000-7f2d665ef000 ---p 00172000 08:06 1966485                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
  7f2d665ef000-7f2d665f9000 r--p 00172000 08:06 1966485                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
  7f2d665f9000-7f2d665fb000 rw-p 0017c000 08:06 1966485                    /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
  7f2d665fb000-7f2d665ff000 rw-p 00000000 00:00 0 
  7f2d665ff000-7f2d66625000 r-xp 00000000 08:06 2110506                    /lib/x86_64-linux-gnu/ld-2.23.so
  7f2d667ff000-7f2d66804000 rw-p 00000000 00:00 0 
  7f2d66821000-7f2d66824000 rw-p 00000000 00:00 0 
  7f2d66824000-7f2d66825000 r--p 00025000 08:06 2110506                    /lib/x86_64-linux-gnu/ld-2.23.so
  7f2d66825000-7f2d66826000 rw-p 00026000 08:06 2110506                    /lib/x86_64-linux-gnu/ld-2.23.so
  7f2d66826000-7f2d66827000 rw-p 00000000 00:00 0 
  7ffe7cad2000-7ffe7caf3000 rw-p 00000000 00:00 0                          [stack]
  7ffe7cb04000-7ffe7cb06000 r--p 00000000 00:00 0                          [vvar]
  7ffe7cb06000-7ffe7cb08000 r-xp 00000000 00:00 0                          [vdso]
  ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
  Aborted (core dumped)
  </code></pre>