title: C++ const accessors and references best practice
body: <p>In attempting to brush up on my C++, I've been trying to find out the best-practice way of creating accessors.</p>
  
  <p>I want to clarify my understanding and find out if what I'm doing is right.  I have several questions, but they seem pretty simple so I've rolled them all into this one Stack Overflow question.</p>
  
  <p>The following is some example code representing what I 'think' is the correct way of doing things:</p>
  
  <pre><code>class MyClass
  {
  private:
      std::string StringMember_;
      int IntMember_;
  
  public:
      MyClass(const std::string &amp;stringInput, const int &amp;intInput) : StringMember_(stringInput), IntMember_(intInput)
      {
      }
  
      const std::string &amp;StringMember() const
      {
          return StringMember_;
      }
  
      void StringMember(const std::string &amp;stringInput)
      {
          StringMember_ = stringInput;
      }
  
      const int &amp;IntMember() const
      {
          return IntMember_;
      }
  
      void IntMember(const int &amp;intInput)
      {
          IntMember_ = intInput;
      }
  };
  </code></pre>
  
  <p>My questions are:</p>
  
  <p>Where my accessors return a <code>const</code> reference variable, ie <code>const std::string</code>, this means that it (my class's member variable) cannot be changed.  Is that correct?</p>
  
  <p>The last <code>const</code> before a method's body indicates that no members of the class for which that method is a part of can be altered, unless they are designated <code>mutable</code>.  Is this also correct?</p>
  
  <p>Where I'm passing in <code>const</code> method parameters, this means that I ensure these parameters are always stored as they were passed in, thus protecting any original variables being passed in from being altered by the method body.  Is this also correct?</p>
  
  <p>With regards to the <code>mutable</code> keyword, under what circumstances would I actually want to use this?  I've been struggling to think of a good scenario where I'd have a const method that needed to modify class members.</p>
  
  <p>Accessors seem like a good idea, even for data that will never be publicly exposed, because it ensures a single-point of entry, allowing for easier debugging and so on.  Am I thinking along the right lines here, or is this in fact totally meaningless, and that there is no need for private accessors?</p>
  
  <p>From a purely syntactical perspective, should I be writing my references like <code>const int&amp; intInput</code> or <code>const int &amp;intInput</code>.  Does it really matter where the ampersand is, or is it just a matter of personal preference?</p>
  
  <p>Finally, is what I'm doing in the example above good practice?  I plan to start working on a larger personal project, and I want to have these core basics down before I start running into problems later.</p>
  
  <p>I was using this as a reference: <a href="https://isocpp.org/wiki/faq/const-correctness" rel="nofollow">https://isocpp.org/wiki/faq/const-correctness</a></p>