title: error: invalid initialization of reference of type 'int&' from expression of type 'const int'
body: <p>This is an unrelated question about the code in <a href="https://stackoverflow.com/questions/11370340/how-do-i-get-the-template-type-of-a-given-element-at-runtime-in-c">this question</a>, regarding the following template function.</p>
  
  <pre><code>template &lt;class T&gt;
  class Object : public Container {
  public:
      T&amp; object;
  
      Object(const T&amp; obj) : object(obj) {}
  };
  </code></pre>
  
  <p>This is the code that calls the constructor:</p>
  
  <pre><code>template &lt;class T&gt;
  void Array::add_element(const T&amp; element)
  {
      vec.push_back(new Object&lt;T&gt;(element));
  }
  </code></pre>
  
  <p>This code compiles fine, but as soon as I add a line in <code>main</code> that calls it:</p>
  
  <pre><code>Array array;
  int i = 3;
  array.add_element(i);
  </code></pre>
  
  <p>I get a compiler warning: <code>error: invalid initialization of reference of type 'int&amp;' from expression of type 'const int'</code>.</p>
  
  <p>What is that about? I passed an <code>int</code> in. Shouldn't it automatically be turned into a <code>const int&amp;</code> for me? Why is the compiler complaining?</p>