title: Deleting array error
body: <p>So I have the following class method (will probably add more if requested):</p>
  
  <p>EDIT 1:
  Here is where paObject gets initialized and how it remains until it reaches <code>setCapacity(int c)</code></p>
  
  <pre><code>template &lt;Object&gt;
  ArrayClass&lt;Object&gt;::ArrayClass()
  {
      _size = 0; //default in case allocation fails
      paObject = new Object[ARRAY_CLASS_DEFAULT_SIZE];
      if (paObject == NULL)
          throw Exception();
      _size = ARRAY_CLASS_DEFAULT_SIZE;
  }
  </code></pre>
  
  <p>It may be important to note that my class Vector extends (or whatever it is in c++) <code>ArrayClass</code>: <code>class MyVector: virtual public ArrayClass&lt;Object&gt;{}</code> and then later on in</p>
  
  <pre><code>template &lt;class Object&gt;
  MyVector&lt;Object&gt;::MyVector() : ArrayClass&lt;Object&gt;()
  {
      _currSize = 0;
      _incFactor = 5;
  }
  </code></pre>
  
  <p>it forces to call the ArrayClass constructor.</p>
  
  <pre><code>    template &lt;Object &gt;    
      void MyVector&lt;Object&gt;::setCapacity(int c)
      {
          int len = _currSize;
          if (len &gt; c) len = c;
          Object* paNew = new Object[c];
          if (paNew == NULL) throw Exception();
          for (int i = 0; i &lt; len; i++)
              paNew[i] = paObject[i];
          if (paObject != NULL)
              delete[] paObject;
          paObject = paNew;
          _size = c;
          if (_currSize &gt; len)
              _currSize = len;
      }
  </code></pre>
  
  <p>When the error happens, the value of c is <code>6</code> and the value of _currSize (a class private int variable) is <code>1</code>. It is also remarkable to remark that paObject is a class pointer of type Object (which is a template... etc. etc.) initialized with an array of Objects of size 1 by the time the error happens (<code>Object* paObject = new Object[1]</code>).</p>
  
  <p>Everything executes fine up until it reaches the line <code>delete[] paObject;</code> at which point it gives me a <code>Expression: _BLOCK_TYPE_IS_VALID(pHead-&gt;nBlockUse)</code> error.</p>
  
  <p>I seriously don't understand what is wrong.
  Help would be appreciated.</p>