title: c++ constructor / destructor
body: <p>I have the following code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class A
  {  
  public:
      A ()
      {
          cout&lt;&lt;"cons"&lt;&lt;endl;
      }
      ~A ()
      {
          cout&lt;&lt;"dest"&lt;&lt;endl;
      }
  };
  
  A
  gokul (void)
  {
      A p;
  
      return p;
  }
  
  int
  main ()
  {
     A a = gokul();
     cout&lt;&lt;"done\n";
  }
  </code></pre>
  
  <p>When I run it. I get the following output:</p>
  
  <p>cons</p>
  
  <p>done</p>
  
  <p>dest</p>
  
  <p>I was expecting the output to be:</p>
  
  <p>cons  --> p created, </p>
  
  <p>cons  --> for a, gokul returning</p>
  
  <p>dest  --> p destroyed, gokul returned</p>
  
  <p>done  </p>
  
  <p>dest  --> a destroyed, main returned</p>
  
  <p>as the local variable "p" will be destroyed when the function gokul returns and the new variable "a" will be created, no? I have compiled with all three standards 03, 11 &amp; 14 and I get the same result.
  ~                          </p>