title: Must I use pointers for my C++ class fields?
body: <p>After reading a question on <a href="https://stackoverflow.com/questions/57483/difference-between-pointer-variable-and-reference-variable-in-c">the difference between pointers and references</a>, I decided that I'd like to use references instead of pointers for my class fields. However it seems that this is not possible, because they cannot be declared uninitialized (right?).</p>
  
  <p>In the particular scenario I'm working on right now, I don't want to use normal variables (what's the correct term for them by the way?) because they're automatically initialized when I declare them.</p>
  
  <p>In my snippet, bar1 is automatically instantiated with the default constructor (which isn't what I want), &amp;bar2 causes a compiler error because you can't use uninitialized references (correct?), and *bar3 is happy as larry because pointers can be declared uninitialized (by the way, is it best practice to set this to NULL?).</p>
  
  <pre><code>class Foo
  {
  public:
      Bar bar1;
      Bar &amp;bar2;
      Bar *bar3;
  }
  </code></pre>
  
  <p>It looks like I have to use pointers in this scenario, is this true? Also, what's the best way of using the variable? The -> syntax is a bit cumbersome... Tough luck? What about <a href="https://stackoverflow.com/questions/417481/pointers-smart-pointers-or-shared-pointers">smart pointers</a>, etc? Is this relevant?</p>
  
  <h3>Update 1:</h3>
  
  <p>After attempting to implement a reference variable field in my class and initializing it in the constructor, why might I receive the following error?</p>
  
  <pre><code>../src/textures/VTexture.cpp: In constructor ‘vimrid::textures::VTexture::VTexture()’:
  ../src/textures/VTexture.cpp:19: error: uninitialized reference member ‘vimrid::textures::VTexture::image’
  </code></pre>
  
  <p>Here's the real code:</p>
  
  <pre><code>// VTexture.h
  class VTexture
  {
  public:
      VTexture(vimrid::imaging::ImageMatrix &amp;rImage);
  private:
      vimrid::imaging::ImageMatrix &amp;image;
  }
  
  // VTexture.cpp
  VTexture::VTexture(ImageMatrix &amp;rImage)
      : image(rImage)
  {
  }
  </code></pre>
  
  <p>I've also tried doing this in the header, but no luck (I get the same error).</p>
  
  <pre><code>// VTexture.h
  class VTexture
  {
  public:
      VTexture(vimrid::imaging::ImageMatrix &amp;rimage) : image(rImage) { }
  }
  </code></pre>
  
  <h3>Update 2:</h3>
  
  <p><strong>Fred Larson</strong> - Yes! There is a default constructor; I neglected it because I thought it wasn't relevant to the problem (how foolish of me). After removing the default constructor I caused a compiler error because the class is used with a std::vector which requires there to be a default constructor. So it looks like I must use a default constructor, and therefore must use a pointer. Shame... or is it? :)</p>