title: Protecting private member return by reference from accidental reassignment
body: <p>I have the following function prototype:</p>
  
  <pre><code>virtual CBuffer&amp; GetData(unsigned int&amp; samples, unsigned int&amp; stride);
  </code></pre>
  
  <p>This returns a reference to a CBuffer object that is a private member of my class.</p>
  
  <p>The problem is that if the following is written, the internal private member that the method returns will be reassigned.</p>
  
  <pre><code>CBuffer&amp; CPlug::ProcessData(unsigned int&amp; samples, unsigned int&amp; stride)
  {
    /* get the data from the source */
    CBuffer&amp; buffer = m_source.GetData(samples, stride);
  
    if (m_postProcess)
      buffer = PostProcess(buffer, samples, stride);
  
    return buffer;
  }
  </code></pre>
  
  <p>Obviously this can be fixed by doing the following:</p>
  
  <pre><code>CBuffer&amp; CPlug::ProcessData(unsigned int&amp; samples, unsigned int&amp; stride)
  {
    /* get the data from the source */
    CBuffer* buffer = &amp;m_source.GetData(samples, stride);
  
    if (m_postProcess)
      buffer = &amp;PostProcess(*buffer, samples, stride);
  
    return *buffer;
  }
  </code></pre>
  
  <p>But I want to know if there is some way to prevent this, possibly through some use of <code>const</code> that I am unaware of?</p>
  
  <p>At this point I am of the opinion that I should just convert to using pointers, but it would be nice to know if it could be done.</p>