C++ destructor for class contains array of ptr to objects : <p>For example if we have 2 classes</p>

<pre><code>class A{
  int size;
  A** arr;
}
class B{
  int size;
  A** arr;
}
</code></pre>

<p>For A's constructor I wrote:</p>

<pre><code>A::A(){
  this-&gt;arr=new A* [20];
}
</code></pre>

<p>For B's constructor I wrote:</p>

<pre><code>B:B(){
  this-&gt;arr=new A* [20];
}
</code></pre>

<p>For A's destroctor I wrote: </p>

<pre><code>A:~A(){
  for(int i=0;i&lt;this-&gt;size;i++){
    delete this-&gt;arr[i];
  }
  delete [] this-&gt;arr;
}
</code></pre>

<p>For B's destructor I wrote:</p>

<pre><code>  B:~B(){
  for(int i=0;i&lt;this-&gt;size;i++){
    delete this-&gt;arr[i];
  }
  delete [] this-&gt;arr;
}
</code></pre>

<p>Note that the size will grow as I put more obj into the arr.
Now my question is, while I am testing, there's nothing wrong, but after the main program returns, it gives me segfault?</p>
