title: Should I prefer pointers or references in member data?
body: <p>This is a simplified example to illustrate the question:</p>
  
  <pre><code>class A {};
  
  class B
  {
      B(A&amp; a) : a(a) {}
      A&amp; a;
  };
  
  class C
  {
      C() : b(a) {} 
      A a;
      B b; 
  };
  </code></pre>
  
  <p>So B is responsible for updating a part of C.  I ran the code through lint and it whinged about the reference member: <a href="http://gimpel-online.com/MsgRef.html#1725" rel="noreferrer">lint#1725</a>.
  This talks about taking care over default copy and assignments which is fair enough, but default copy and assignment is also bad with pointers, so there's little advantage there.</p>
  
  <p>I always try to use references where I can since naked pointers introduce uncertaintly about who is responsible for deleting that pointer.  I prefer to embed objects by value but if I need a pointer, I use auto_ptr in the member data of the class that owns the pointer, and pass the object around as a reference.</p>
  
  <p>I would generally only use a pointer in member data when the pointer could be null or could change.  Are there any other reasons to prefer pointers over references for data members?</p>
  
  <p>Is it true to say that an object containing a reference should not be assignable, since a reference should not be changed once initialised?</p>