title: How can I initialize a reference attribute in my class
body: <p>I have a class which has a private attribute which is a reference to another class:</p>
  
  <pre><code>class A {
  public:
     A(); 
     A(B&amp; anotherB);
  private:
    B&amp; bRef;
  }
  </code></pre>
  
  <p>In my A(B&amp; anotherB), I can do this:</p>
  
  <pre><code>  A::A(B&amp; anotherB)
     : bRef(anotherB) {
  }
  </code></pre>
  
  <p>But what about A()?  I tried this:</p>
  
  <pre><code>   A::A()
      : bRef(B()) {}
  </code></pre>
  
  <p>But I get this error 'error: invalid initialization of non-const reference of type ‘B&amp;’ from a temporary of type ‘B’.</p>
  
  <p>How can I call initialize B reference in A with the default constructor of B?</p>
  
  <p>Thank you.</p>