title: Why can't a const method return a non-const reference?
body: <p>Why won't the method <code>getRanks()</code> below compile, and how can I fix it gracefully?</p>
  
  <p>All I want do is define a member accessor method that returns a reference to a member. The reference is not <code>const</code> since I might well modify what it refers to later. But since the member method does not modify the object, I declare it <code>const</code>. The compiler (clang, std=c++11) then insists that there is a "binding of reference" that "drops qualifiers". But I'm NOT dropping qualifiers, am I? And if I am, why:</p>
  
  <pre><code>struct teststruct{
    vector&lt;int&gt; ranks;
    vector&lt;int&gt;&amp; getRanks()const{
      return ranks;
    }
  };
  </code></pre>
  
  <p>Now, the code compiles if I change the return statement to cast away the const:</p>
  
  <pre><code>return const_cast&lt;vector&lt;int&gt;&amp;&gt;(ranks);
  </code></pre>
  
  <p>But "ranks" should not be const in the first place, I don't see why I need to const_cast the const away. I don't even know if it's safe to do this.</p>
  
  <p>Anyway, is there a cleaner to write this method? Can someone explain why such a simple common-sense method fails? I do want to declare the <code>getRanks()</code> method "<code>const</code>" so that I can call it from other <code>const</code> methods. </p>