title: Is it safe to return *this as a reference?
body: <p>Returning reference to this object is often used in <a href="https://stackoverflow.com/questions/12038509/c-operator-return-reference-to-this">assignment operator overloading</a>. It is also used as a base for <a href="https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Named_Parameter">named parameters idiom</a> which allows to initialize object by chain of calls to setter methods: <code>Params().SetX(1).SetY(1)</code> each of which returns reference to *this.</p>
  
  <p>But is it correct to return reference to <code>*this</code>. What if we call the method returning reference to this for a temporary object:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class Obj
  {
  public:
      Obj(int n): member(n) {}
      Obj&amp; Me() { return *this; }
  
      int member;
  };
  
  Obj MakeObj(int n)
  {
      return Obj(n);
  }
  
  int main()
  {
      // Are the following constructions are correct:
      std::cout &lt;&lt; MakeObj(1).Me().member &lt;&lt; std::endl;
      std::cout &lt;&lt; Obj(2).Me().member &lt;&lt; std::endl;
      Obj(3).Me() = Obj(4);
  
      return 0;
  }
  </code></pre>