title: How do I write a const accessor that returns a reference to a member object, so it might be edited?
body: <p>Here is the problem. I wrote this function to return a reference to the i element of a member vector, so this element could be edited. Here is the code:</p>
  
  <pre><code>Letter&amp; Literal::get (int i) const {
  
     return lit_m.at (i); //Vector of Letter objects
  }
  </code></pre>
  
  <p>But g++ won't let me assign that element to a non-const reference:</p>
  
  <pre><code>g++ -o literal.o -c literal.cpp
  literal.cpp: In member function ‘Letter&amp; Literal::get(int) const’:
  literal.cpp:34: error: invalid initialization of reference of type ‘Letter&amp;’ from expression of type ‘const Letter’
  </code></pre>
  
  <p>How could it be solved? My idea is to build up a function like the at() function of vectors, so it would be const as it doesn't edit the object itself, but it should let me edit the returned object...Is it possible?</p>
  
  <p>SOLVED: I just had to overload the function :), so declare a const and a non-const version. I was afraid that const and non-const overloading wasn't permitted, but I saw that that const changes the argument list, making it possible.</p>