title: Assigning an Array to Another Array on the Heap C++
body: <p><code>T</code> is = to char<br>
  <code>counts_</code> is an array of integers stored on the heap<br>
  <code>values_</code> is an array of arrays on the heap  </p>
  
  <p>Problem arrives in the if statement, when I try to delete <code>tmpe</code> I get an error.  If I comment the delete statement out, the code runs but it just keeps pointing all of my pointers in <code>values_</code> to the same array.  The idea of the code is to create a new array containing the values of one of the selected <code>values_</code> arrays and then add one extra value to it.  Then re-assign it back to the spot in the <code>values_</code> array that I took it from.  The <code>tmpe</code> array is holding the correct values up to the point that I attempt to delete the pointer to it.  I get a Aborted (core dumped) error upon running my entire program.  </p>
  
  <pre><code>if (initialized(n) == true)
  {   
      T *tmpe = new T[counts_[n] + 1];
      for (size_type i = 0; i &lt; counts_[n]; i++)
      {
          tmpe[i] = values_[n][i];
      }
      tmpe[counts_[n]] = val;
      delete [] values_[n];
      values_[n] = tmpe;
      delete [] tmpe;
      counts_[n]++;
  }
  else
  {
      T *tmpd = new T[counts_[n] + 1];
      tmpd[counts_[n]] = val;
      delete [] values_[n];
      values_[n] = tmpd;
      delete [] tmpd;
      counts_[n]++;
  }
  </code></pre>