title: C++ Destructor inheritance
body: <pre><code>/* Problem 50 */
  #include &lt;iostream&gt;
  using namespace std;
  
  class a {
      char ach;
    public:
      a(char c) { ach = c - 1; }
      ~a(); // defined below
      virtual void out(ostream &amp;os) {
        if ('m' &lt; ach)
          os &lt;&lt; ach &lt;&lt; char(ach+7) &lt;&lt; char(ach+6) &lt;&lt; ' ';
        else
          os &lt;&lt; ach &lt;&lt; ach &lt;&lt; ach;
      }
  };
  
  class b: public a {
      char bach;
    public:
      b(char c1, char c2) : a(c1) { bach = c2-1; }
      void out(ostream &amp;os) {
        a::out(os);
        os &lt;&lt; ' ' &lt;&lt; bach &lt;&lt; char(bach + 11);
      }
  };
  
  ostream &amp;operator&lt;&lt;(ostream &amp;os, a &amp;x) {
    x.out(os);
    return os;
  }
  
  a::~a() {
    cout &lt;&lt; *this; // calls above operator
  }
  
  int main() {
    b var1('n', 'e');
    a var2('o');
    cout &lt;&lt; "Homer says: " &lt;&lt; var1 &lt;&lt; '\n';
    return 0;
  }
  </code></pre>
  
  <p>I'm confuse why only two object being destruct while there are three object being construct</p>
  
  <p>I also have put <code>cout</code> on each of the construct on the <code>base_class</code> and the <code>derived_class</code> to see how many were construct and I was right about the number of constructed object, but I was wrong when I did the destruct.</p>
  
  <p>If anyone could please point me out why the last destruct didn't apply to the first object that being create?</p>