Objects and copy ctors created without RVO in C++
<p>I am new to C++. Please consider the following code:</p>

<pre><code>class foo 
{ 
 int f; 

 public: 
   foo(int f1=0) : f(f1) { 
   cout&lt;&lt;"In conversion ctor\n"; 
 } 

foo(const foo &amp; rhs) : f(rhs.f) 
{ 
    cout&lt;&lt;" In copy ctor\n"; 
} 

 foo&amp; operator=(const foo &amp; that) 
{ 
    f=that.f; 
    cout&lt;&lt;"In = optor\n"; 
    return *this; 
} 

}; 

 foo rbv() 
  { 
    foo obj(9); 
    return obj;                        //named return by value [def. 1] 
  } 

   foo caller() 
   { 
      return rbv();              // return by value [def. 2] 
   } 

int main(void) 
{ 
   foo box=caller(); 
   return 0; 
 }
</code></pre>

<ol>
<li>Are the definitions for RBV and NRBV correct as indicated in the 
comments? </li>
<li>Is it mandatory to have an accessible copy ctor defined though it 
is not called during RVO? </li>
<li><p>Without RVO, in the code blocks</p>

<pre><code>   foo rbv() 
    { 
     foo obj(9); 
     return obj; 
    } 

    foo ret= rbv();
</code></pre></li>
</ol>

<p>Are the following steps correct in creation of 'ret' </p>

<p>(1) a temporary ( say obj_temp) is created using copy ctor from obj, 
 stack object 'obj' destroyed, </p>

<p>(2) ret is copy constructed from obj_temp, obj_temp destroyed later; </p>

<p>which implies there are three objects, 'obj' , 'obj_temp' and 'ret' and two copy ctors involved.</p>
