title: What does `invalid initialization of non-const reference` mean?
body: <p>When compiling this code I get the following <a href="http://codepad.org/ZWzFIYzY" rel="nofollow noreferrer">error</a>:</p>
  
  <blockquote>
    <p>In function 'int main()':
    Line 11: error: invalid initialization of non-const reference of type 'Main&amp;' from a temporary of type 'Main'</p>
  </blockquote>
  
  <p>Here's my code:</p>
  
  <pre><code>template &lt;class T&gt;
  struct Main
  {
      static Main tempFunction(){
         return Main();
      }
  };
  
  int main()
  {
     Main&lt;int&gt; &amp;mainReference = Main&lt;int&gt;::tempFunction(); // &lt;- line 11
  }
  </code></pre>
  
  <p>I don't understand why? Can anyone explain?</p>