title: Delete pointers from a map
body: <p>There is a map, it maps an <code>int</code> to a <code>Test*</code>.</p>
  
  <p>All <code>Test*</code> pointers are allocated before and assigned to the map later. Then, I'm <code>delete</code><em>ing</em> values of map and set them to <code>null</code>.</p>
  
  <p>After that, It checks validity of <code>one</code>, and it supposed to be <code>null</code>. <strong>But</strong>, <code>one</code> is not <code>null</code>.</p>
  
  <pre><code>#include &lt;QString&gt;
  #include &lt;QMap&gt;
  #include &lt;QDebug&gt;
  
  class Test {
      QString name;
  public:
      Test(const QString &amp;name) : name(name) {}
      QString getName() const { return name; }
  };
  
  int main() {
      QMap&lt;int, Test*&gt; map;
  
      Test *one = new Test("one");
      Test *two = new Test("two");
      Test *three = new Test("three");
  
      map.insert(1, one);
      map.insert(2, two);
      map.insert(3, three);
  
      for (auto itr = map.begin(); itr != map.end(); itr++) {
          Test *x = *itr;
          if (x) {
              delete x;
              x = 0; // ** Sets null to the pointer ** //
          }
      }
  
      if (one) // ** Here one is not 0 ?! ** //
          qDebug() &lt;&lt; one-&gt;getName() &lt;&lt; endl; // ** And then here crashes ** //
  }
  </code></pre>
  
  <p>I think, I missed something when I'm <code>delete</code><em>ing</em> them in the loop.</p>
  
  <p>How can it fixed?</p>
  
  <p>Second question is, is it correctly <code>delete</code><em>s</em> the allocated pointers?</p>