title: const objects as a function parameter
body: <p>Consider the following code snippet:</p>
  
  <pre><code>class MyClass {
      int x;
    public:
      MyClass(int val) : x(val) {}
      const int&amp; get() const {return x;}
  };
  
  void print (const MyClass&amp; arg) {
    cout &lt;&lt; arg.get() &lt;&lt; '\n';
  }
  
  int main() {
    MyClass foo (10);
    print(foo);
  
    return 0;
  }
  </code></pre>
  
  <p>Whether I add a <code>const</code> modifier before the instatiatation of MyClass or not, the program successfully compiles (without any warning) and prints <code>10</code>. Why can <code>print</code> accept a non-<code>const</code> argument? Or, in other words, what is the function of the <code>const</code> modifier in the function parameter? Why can the formal and actual parameters of a function have different types (or modifiers)?</p>
  
  <p>I have tried both GCC (4.8.2) and Clang (3.4) with <code>-Wall -std=c++11</code> on Ubuntu 14.04, and the results were the same (no errors/warnings). I have also searched "c++ const object function" but didn't get anything that looked promising.</p>