title: C++, Member function returning const reference to vector containing pointers to const objects
body: <p>I have a class with a member vector of pointers to objects. Now I want an accessor method to return a const reference to this vector. I also want the caller method to be unable to edit the objects pointed to by the vector's pointers, i.e. the pointers should point to const objects. Here is my erroneous code:</p>
  
  <pre><code>class Foo
  {
  private:
      vector&lt;Foo*&gt; myFoos;
  public:
      const vector&lt;const Foo*&gt; &amp;getMyFoos(void)
      {
          return myFoos; //Doesn't work since vector&lt;Foo*&gt; cannot be cast to vector&lt;const Foo*&gt;
      }
  }
  </code></pre>
  
  <p>I have seen answers to similar questions where the solution is to make a copy of the vector myFoos where the copy is of the correct type. Is there anyway to do this without making a copy, since the myFoos vector may be very large?</p>