title: Invalid initialization of non-const reference of type
body: <p>In the following code, I'm not able to pass a temporary object as argument to the <code>printAge</code> function:</p>
  
  <pre><code>struct Person {
    int age;
    Person(int _age): age(_age) {}
  };
  
  void printAge(Person &amp;person) {
     cout &lt;&lt; "Age: " &lt;&lt; person.age &lt;&lt; endl;
  }
  
  int main () {
    Person p(50);
    printAge(Person(50));  // fails!
    printAge(p);
    return 0;
  }
  </code></pre>
  
  <p>The error I get is: </p>
  
  <pre><code>error: invalid initialization of non-const reference of type ‘Person&amp;’ from an rvalue of type ‘Person’
  </code></pre>
  
  <p>I realize that this is something to do with passing an lValue to a function expecting a rValue... Is there a way to convert my lValue to rValue by using std::move or something? I tried taking a constant parameter, but that does not seem to work.</p>