title: const vector implies const elements?
body: <p>Does <code>const vector&lt;A&gt;</code> mean that its elements are <code>const</code>as well?</p>
  
  <p>In the code below,</p>
  
  <p><code>v[0].set (1234);</code>  in <code>void g ( const vector&lt;A&gt; &amp; v )</code>
  produces the  compiler error</p>
  
  <blockquote>
    <p>const.cpp:28:3: error: member function 'set' not viable: 'this'
    argument has
          type 'const value_type' (aka 'const A'), but function is not marked const</p>
  </blockquote>
  
  <p>Why?</p>
  
  <p>But <code>(*v[0]).set(1234);</code> in <code>void h ( const vector&lt;A *&gt; &amp; v )</code>
  is OK for the compiler.</p>
  
  <p>What's the difference between the versions?</p>
  
  <pre><code>// ...........................................................
  class A {
  private:
    int a;
  public:
    A (int a_) : a (a_) { }
    int get () const { return a; }
    void set (int a_) { a = a_; }
  };
  
  // ...........................................................
  void g ( const vector&lt;A&gt; &amp; v ) {
    cout &lt;&lt; v[0].get();
    v[0].set (1234); 
  } // ()
  
  // ...........................................................
  void h ( const vector&lt;A *&gt; &amp; v ) {
    cout &lt;&lt; (*v[0]).get();
    (*v[0]).set(1234);
  } // ()
  </code></pre>