title: Constructor/Destructor call order on stack
body: <p>I have the following simple code:</p>
  
  <pre><code>class A
  {
      int a;
  public:
      A(int a) : a(a) { cout &lt;&lt; "Constructor a=" &lt;&lt; a &lt;&lt; endl; }
      ~A()            { cout &lt;&lt; "Destructor  a=" &lt;&lt; a &lt;&lt; endl; }
      void print()    { cout &lt;&lt; "Print       a=" &lt;&lt; a &lt;&lt; endl; }
  };
  
  void f()
  {
      A a(1);
      a.print();
      a = A(2);
      a.print();
  }
  
  int main()
  {
      f();
      return 0;
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>Constructor a=1
  Print       a=1
  Constructor a=2
  Destructor  a=2
  Print       a=2
  Destructor  a=2
  </code></pre>
  
  <p>I find that there are two destructor calls with <code>a=2</code> and none with <code>a=1</code> while there is one constructor call for each case. So how are contructors and destructros called in this case?</p>