title: Why not use pointers for everything in C++?
body: <p>Suppose that I define some class:</p>
  
  <pre><code>class Pixel {
      public:
        Pixel(){ x=0; y=0;};
        int x;
        int y;
  }
  </code></pre>
  
  <p>Then write some code using it. Why would I do the following?</p>
  
  <pre><code>Pixel p;
  p.x = 2;
  p.y = 5;
  </code></pre>
  
  <p>Coming from a Java world I always write:</p>
  
  <pre><code>Pixel* p = new Pixel();
  p-&gt;x = 2;
  p-&gt;y = 5;
  </code></pre>
  
  <p>They basically do the same thing, right?
  One is on the stack while the other is on the heap, so I'll have to delete it later on. Is there any fundamental difference between the two? Why should I prefer one over the other?</p>