title: Storing the content of a reference passed as a parameter
body: <p>I am programming in C++/Qt. Do these code snippets correctly save the content of a reference by copying?</p>
  
  <p>With Initialization List:</p>
  
  <pre><code>Foo(const Bar &amp;bar) : bar(bar) { }
  Bar bar; //member variable of Foo class
  </code></pre>
  
  <p>In a Setter-Method:</p>
  
  <pre><code>void TestClass::setName(const QString &amp;name) {
      this-&gt;name = name;
  }
  QString name; //member variable of TestClass class
  </code></pre>
  
  <p>If it does, does this copy the copy?:</p>
  
  <pre><code>void TestClass::setName(const QString name) {
      this-&gt;name = name;
  }
  QString name; //member variable of TestClass class
  </code></pre>
  
  <p>Does this lead to undefined behavior, because the referenced object might be deconstructed early?:</p>
  
  <pre><code>Foo(Bar &amp;bar) : bar(bar) { }
  Bar &amp;bar; //member variable of Foo class
  </code></pre>
  
  <p>Is it bad style to store the content of a passed reference? What would be a better way to pass arguments that need to be stored?</p>