title: How does this example work in Bjarne Stroustrup's C++ Programming Language works?
body: <p>I'm reading <em><a href="https://rads.stackoverflow.com/amzn/click/com/0321563840" rel="nofollow noreferrer" rel="nofollow noreferrer">The C++ Programming Language, 4th Edition</a></em> (by <a href="http://en.wikipedia.org/wiki/Bjarne_Stroustrup" rel="nofollow noreferrer">Bjarne Stroustrup</a>) about <a href="/questions/tagged/references" class="post-tag" title="show questions tagged &#39;references&#39;" rel="tag">references</a>.</p>
  
  <p>He has the following code example:</p>
  
  <pre><code>void f (const vector&lt;double&gt;&amp; v){
      double d1 = v[1];
      v[2] = 7;
  
      v.push_back(d1);
  } 
  </code></pre>
  
  <p>My question is: since <code>v</code> is passed as const how can we change <code>v</code> in second and third statements in the function?</p>
  
  <p>I tried compiling the code and it does not work:</p>
  
  <blockquote>
    <p>error: assignment of read-only location</p>
  </blockquote>
  
  <p>So what am I missing here?  I doubt it is Bjarne who made a mistake :D</p>
  
  <p>Thanks</p>