title: Const reference as class member
body: <p>Even if the subject was discussed many times around here, I can't find a conclusive explanation regarding my particular case. Will <code>const</code> extend the lifetime of the <code>RefTest</code> temporary? Is the below example legal?</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class RefTest
  {
  public:
      RefTest(const std::string &amp;input) : str(input) {}
      ~RefTest () {std::cout &lt;&lt; "RefTest" &lt;&lt; std::endl;}
  private:
      std::string str;
  };
  
  class Child
  {
  public:
      Child (const RefTest &amp;ref) : ref_m(ref) {}
      ~Child () {std::cout &lt;&lt; "Test" &lt;&lt; std::endl;}
  private:
      const RefTest &amp;ref_m;
  };
  
  class Test
  {
  public:
      Test () : child(RefTest("child")) {}//Will the temporary get destroyed here?
      ~Test () {std::cout &lt;&lt; "Test" &lt;&lt; std::endl;}
  private:
      const Child child;
  };
  
  int main ()
  {
     Test test;
  }
  </code></pre>