title: Temporary objects - when are they created, how do you recognise them in code?
body: <p>In Eckel, Vol 1, pg:367</p>
  
  <pre><code>//: C08:ConstReturnValues.cpp
  // Constant return by value
  // Result cannot be used as an lvalue
  class X {
     int i;
  public:
     X(int ii = 0);
     void modify();
  };
  
  X::X(int ii) { i = ii; }
  
  void X::modify() { i++; }
  
  X f5() {
     return X();
  }
  
  const X f6() {
     return X();
  }
  
  void f7(X&amp; x) { // Pass by non-const reference
     x.modify();
  }
  
  int main() {
     f5() = X(1); // OK -- non-const return value
     f5().modify(); // OK
  // Causes compile-time errors:
  //! f7(f5());
  //! f6() = X(1);
  //! f6().modify();
  //! f7(f6());
  } ///:~
  </code></pre>
  
  <p>Why does <code>f5() = X(1)</code> succed? What is going on here???</p>
  
  <p>Q1. When he does <code>X(1)</code> - what is going on here? Is this a constructor call - 
  shouldn't this then read <code>X::X(1);</code> Is it class instantiation - isn't class 
  instantiation something like: <code>X a(1);</code> How does the compiler determine what 
  <code>X(1)</code> is?? I mean.. name decoration takes place so.. <code>X(1)</code> the constructor 
  call would translate to something like: <code>globalScope_X_int</code> as the function 
  name.. ???</p>
  
  <p>Q2. Surely a temporary object is used to  store the resulting object that <code>X(1)</code>
  creates and then would't that be then assigned to the object <code>f5()</code> returns 
  (which would also be a temporary object)? Given that <code>f5()</code> returns a temporary
  object that will be soon be discarded, how can he assign one constant temporary
  to another constant temporary??? Could someone explain clearly why:
  <code>f7(f5());</code> should reult in a constant temporary and not plain old <code>f5();</code></p>