title: Const Object, Const Member Function and Mutable Variable in C++
body: <p>I know that a <code>const</code> object can't call a non-<code>const</code> member function. It says so in the C++14 Standard (ISO/IEC 14882:2014) Section 9.3.2, Paragraph 3:</p>
  
  <blockquote>
    <p>A <em>cv-qualified</em> member function can be called on an object-expression (5.2.5) only if the object-expression is as cv-qualified or less-cv-qualified than the member function.</p>
  </blockquote>
  
  <p>Does this constraint make sense if the member function does not modify anything? Or if the member function modifies a mutable variable? For example: </p>
  
  <pre><code>class My_Class {
      public:
          mutable int value;
          void function( int x ) const { value = x; } //     Correct
        //void function( int x )       { value = x; } // Not Correct
          My_Class() : value(0) {}
  };
  
  int main(){
  
      const My_Class obj;
      obj.function( 1 );
  
      return 0;
  }
  </code></pre>
  
  <p>In this specific case, if the function is <code>const</code>, the program is correct and the function can modify a variable of the <code>const</code> object. If the function is not <code>const</code>, the program is not correct. So in the end, I need to write <code>const</code> to be able to modify something, which should be the opposite purpose of <code>const</code>.</p>
  
  <p>Does anyone know why this rule is designed this way?</p>