title: Error: cannot bind non-const lvalue reference of type ‘int&’ to an rvalue of type ‘int’
body: <p>I need to create a <code>Bar</code> object, which has a private object <code>Foo f</code>.</p>
  <p>However, the value of <code>Foo</code> object parameter should be passed by the specific method <code>int genValue()</code>.</p>
  <p>If I initialize  <code>f</code> in the constructor scope <code>Bar(){...}</code>, the compiler yell error, something like there is no constructor <code>Foo()</code>.</p>
  <p>If I construct like this <code>Bar(): f(genValue())</code>, the compiler yells the error:</p>
  <pre><code>test.cpp: In constructor ‘Bar::Bar()’:
  test.cpp:16:19: error: cannot bind non-const lvalue reference of type ‘int&amp;’ to an rvalue of type ‘int’
   Bar(): f(genValue()){    
              ~~~~~~~~^~
  test.cpp:7:2: note:   initializing argument 1 of ‘Foo::Foo(int&amp;)’    
   Foo(int &amp;x) {    
   ^~~
  </code></pre>
  <p>Example code:</p>
  <pre><code>class Foo {
  public:
      Foo(int &amp;x) {
          this-&gt;x = x;
      }
  private:
      int x;
  };
  
  class Bar {
  public:
      Bar(): f(genValue()){
      }
  private:
      Foo f;
  
      int genValue(){
          int x;
          // do something ...
          x = 1;
          return x;
      }
  };
  
  int main() {
  
      Bar bar ();
  
      return 0;
  }
  </code></pre>
  <p>How can I fix the problem, if I don't want to modify <code>Foo</code> class and its argument value should be passed from <code>genValue()</code>?  And, I don't want to use pure pointer (*), but a solution with smart pointer is okay!</p>