title: C++ delete pointer array - double free or corruption
body: <p>This is just a test project to understand how inheritance works. Cat is a subclass of Mammal, which again is a subclass of Animal.</p>
  
  <pre><code>int main()
  {
      Cat* cat1 = new Cat("nosy grey", 1.0d, 3);
      Cat* cat2 = new Cat("purply green", 2.0d, 4);
  
      Cat* cats[] = {cat1, cat2};
  
      delete [] cats;
   }
  </code></pre>
  
  <p>So I can't really do that, because then I get this.</p>
  
  <pre><code>*** Error in `/home/max/git/info-2-ss/Blatt3/Aufgabe2/main.exe': double free or corruption (out): 0x00007fff55fd7b10 ***
  ======= Backtrace: =========
  /lib/x86_64-linux-gnu/libc.so.6(+0x80a46)[0x7f3a07452a46]
  /home/max/git/info-2-ss/Blatt3/Aufgabe2/main.exe[0x40178e]
  /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7f3a073f3ea5]
  /home/max/git/info-2-ss/Blatt3/Aufgabe2/main.exe[0x400d39]
  </code></pre>
  
  <p>I output when my constructors and destructors are called, so when my Cats get created I get something like this:</p>
  
  <pre><code>Called ctor of Animal with age: 3
  Called ctor of Mammal with hairLength: 1
  Called ctor of Cat with eyecolor: nosy grey
  </code></pre>
  
  <p>When I change my code a bit so it reads:</p>
  
  <pre><code>delete [] *cats;
  </code></pre>
  
  <p>then I would've expected that my dtors get called like this for every Cat:</p>
  
  <pre><code>Called dtor of Cat
  Called dtor of Mammal 
  Called dtor of Animal 
  </code></pre>
  
  <p>instead I get this single line:</p>
  
  <pre><code>Called dtor of Cat
  </code></pre>
  
  <p>Summary:
  How can I effectively delete my arrays, so that all my dtors get called?</p>