title: Using a getter with a smart pointer
body: <p>Let's say I have the following class:</p>
  
  <pre><code>#include "ClassB.h"
  #include &lt;memory&gt;
  
      class A
      {
  
        private:
          std::shared_ptr&lt;ClassB&gt; aClassB;
  
        public:
          ClassA();
          virtual ~ClassA();
  
          std::shared_ptr&lt;ClassB&gt; getClassB() const{
               return ClassB;
           }
      };
  </code></pre>
  
  <p>Now I can call <code>ClassA.getClassB()</code> to obtain the smart pointer that points to member variable <code>aClassB</code>. However, the problem is that I can use this smart pointer to actually change member variable <code>aClassB</code>, which I don't want. So basically I want to implement something like this:</p>
  
  <pre><code>std::shared_ptr&lt;const ClassB&gt; getClassB() const{
                   return ClassB;
  </code></pre>
  
  <p>However, this does not work because <code>aClassB</code> is not a <code>const</code>. I don't want to make <code>aClassB</code> a constant within <code>classA</code>, because there are member functions of <code>ClassA</code> that should be able to update this aClassB member variable.</p>
  
  <p>Any suggestions how I can get <code>aClassB</code> using the get functions within other classes, but without allowing changes made to <code>aClassB</code> from other classes.</p>