How do virtual destructors work?
<p>I am using gcc. I am aware how the virtual destructors solve the problem when we destroy a derived class object pointed by a base class pointer. I want to know how do they work?</p>

<pre><code>class A
{
      public:
      A(){cout&lt;&lt;"A constructor"&lt;&lt;endl;}
     ~A(){cout&lt;&lt;"A destructor"&lt;&lt;endl;}

};

class B:public A
{
      public:
      B(){cout&lt;&lt;"B constructor"&lt;&lt;endl;}
      ~B(){cout&lt;&lt;"B destructor"&lt;&lt;endl;}
};       

int main()
{
  A * a = new B();
  delete a;    
  getch();
  return 0;   
} 
</code></pre>

<p>When I change A's destructor to a virtual function, the problem is solved. What is the inner working for this. Why do I make A's destructor virtual. I want to know what happens to the vtable of A and B?</p>
