title: Modyfying temporary object
body: <p>Can someone tell why <code>test(2)</code> object is destroyed after <code>test_method()</code> call?</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;string&gt;
  
  using namespace std;
  
  class test
  {
      int n;
  
      public:
      test(int n) : n(n)
      {
          cout &lt;&lt; "test: " &lt;&lt; n &lt;&lt; endl;
      }
  
      ~test()
      {
          cout &lt;&lt; "~test: " &lt;&lt; n &lt;&lt; endl;
      }
  
      test &amp; test_method()
      {
          cout &lt;&lt; "test_method: " &lt;&lt; n &lt;&lt; endl;
          return *this;
      }
  };
  
  int main(int argc, const char *argv[])
  {
      cout &lt;&lt; "main start" &lt;&lt; endl;
      const test &amp;test1 = test(1);
      const test &amp;test2 = test(2).test_method();
      cout &lt;&lt; "main end" &lt;&lt; endl;
  }
  </code></pre>
  
  <p>Output is:</p>
  
  <pre><code>main start
  test: 1
  test: 2
  test_method: 2
  
  ~test: 2
  main end
  ~test: 1
  </code></pre>