title: C++ deleting pointers from vector causes heap error
body: <p>I have a vector of pointers to objects of my base class and then I store objects from derived class in it. The way I add pointers is quite obvious </p>
  
  <pre><code>std::vector&lt;Element*&gt; mvGates;
  ...
  mvGates.push_back(new Node(x, y));
  </code></pre>
  
  <p>And when my program is about to be closed those pointers are freed in 'for' loop</p>
  
  <pre><code> for (int i=0; i&lt;mvGates.size(); ++i)
   {
       delete mvGates[i];
   }
  </code></pre>
  
  <p>At this line my debugger (I'm using Qt Creator) is showing a few lines like that:</p>
  
  <pre><code>Heap block at 14E50F50 modified at 14E50F84 past requested size of 2c
  Invalid address specified to RtlFreeHeap( 00030000, 14E50F58 )
  </code></pre>
  
  <p>What can be the cause, what am I doing wrong? I know that I haven't showed you full code, since it's quite long, but maybe it is enough to tell me my mistake. Probably you will recommend me using smart pointers. I think I will do it but that doesn't answer my question - what can be wrong with this code.</p>
  
  <p>EDIT:
  It was a very simple mistake, you couldn't have noticed it here. In Node class I've declared <code>some_type array[0];</code></p>
  
  <p>And I've been using it as a 2 elements array. I don't know why it didn't cause a SIGSEGV but it was the thing that caused heap error. </p>