title: Member variables clearing while using destructor
body: <p>I was going through some online quiz on C++ and below is the question I bumped into</p>
  
  <p><a href="http://www.interqiew.com/ask?ta=tqcpp01&amp;qn=3" rel="nofollow">http://www.interqiew.com/ask?ta=tqcpp01&amp;qn=3</a> </p>
  
  <pre><code>class A
  {
  public:
      A(int n = 2) : m_i(n) { }
  
      ~A() { std::cout &lt;&lt; m_i; }
  
  protected:
      int m_i;
  };
  
  class B
      : public A
  {
  public:
      B(int n) : m_a1(m_i + 1), m_a2(n) { }
  
  public:
      ~B()
      {
          std::cout &lt;&lt; m_i;
          --m_i;
      }
  
  private:
      A m_a1;
      A m_a2;
  };
  
  int main()
  {
      { B b(5); }
  
      std::cout &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>
  
  <p>Answer comes out to be "2531" - </p>
  
  <p>I was expecting the answer to be "21"  - with rationale as below (which seems to be faulty):</p>
  
  <p>Object B is created with three member variables with starting value 2 -  253  </p>
  
  <p>So when the destructor would be called would be deleted in reverse order.</p>
  
  <p>For this case here destructor will call inherited part - we print 2 we decrement the value and go to 1 and then base while removing would be printed - so answer 21 </p>
  
  <p>How are variables m_a2 and m_a1 getting printed - not able to understand.
  Also its getting printed ( value 53) in the base part ( i.e. Class A)</p>