title: Modifying reference member from const member function in C++
body: <p>I am working on const-correctness of my code and just wondered why this code compiles:</p>
  
  <pre><code>class X
  {
      int x;
      int&amp; y;
  public:
      X(int&amp; _y):y(_y)
      {
      }
  void f(int&amp; newY) const
      {
          //x = 3; would not work, that's fine
          y = newY; //does compile. Why?
      }
  };
  
  int main(int argc, char **argv) 
  {
      int i1=0, i2=0;
      X myX(i1);
      myX.f(i2);
  ...
  }
  </code></pre>
  
  <p>As far as I understand, f() is changing the object myX, although it says to be const. How can I ensure my compiler complains when I do assign to y? (Visual C++ 2008)</p>
  
  <p>Thank a lot!</p>