title: Pushing NULL object into std::vector
body: <p>I have a class called <code>Pixel</code> where I only store the values <code>(x,y)</code>. Then I created a <code>std::vector</code> to store the pixels in a patch and compute some disparity.
  Surprisingly, after some <code>Pixel</code>s are <code>push_back()</code> into the vector I get a NULL reference but I don't see why. Here's my code</p>
  
  <pre><code>std::vector&lt;Pixel*&gt; disparityPatches;
  std::vector&lt;Pixel*&gt; patchPos;
  
  //COMPUTE THE DISPARITY FOR EACH OF THE PIXEL COORDINATES IN THE PATCH
  for (uint iPatchPos = 0; iPatchPos &lt; patchPos.size(); iPatchPos++)
  {
      disparityPatches.push_back(new Pixel(patchPos[iPatchPos]-&gt;getX()+dispNodeX, patchPos[iPatchPos]-&gt;getY()+dispNodeY));
      if( (disparityPatches[disparityPatches.size()-1]) == NULL)
      {
          std::cout &lt;&lt; "WHAT!?" &lt;&lt; std::endl;
      }
  }
  </code></pre>
  
  <p>Can you see why is this hapenning? I've checked that <code>patchPos</code>has the correct data and <code>dispNodeX</code> and <code>dispNodeY</code> have the correct info too.
  It's weird because the first three iterations (iPatchPos = [0,1,2,3]) work fine then i get the NULL reference.</p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>class Pixel
  {
      float _x;
      float _y;
  public:
      Pixel();
      Pixel::Pixel(float x, float y)
      {
         _x = x;
         _y = y;
      }
  
      const float Pixel::getX()
      {
         return _x;
      }
  
      const float Pixel::getY()
      {
         return _y;
      }
  };
  </code></pre>