title: Destructor concept in c++
body: <p>please go through my below code:</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;conio.h&gt;
  using namespace std;
  
  class ClassA
  {
      protected:
      int width, height;
  
      public:
    void set_values(int x, int y)
    {
        width = x;
        height = y;
    }
    virtual int area()
    {
        return 100;
    }
    ~ClassA()
    {
        cout &lt;&lt; "base class destructor called" &lt;&lt; endl;
  
    }
  };
  
  class ClassB : public ClassA
  {
      public :
  int area()
  {
      return (width * height);
  }
  ~ClassB()
  {
      cout &lt;&lt; "derived class destructor called" &lt;&lt; endl;
  }
  };
  int main()
  {
    ClassA *Ptr = new ClassB;
    Ptr-&gt;set_values(10, 20);
    cout &lt;&lt; Ptr-&gt;area() &lt;&lt; endl;
    delete Ptr;
       return 0;
  } 
  </code></pre>
  
  <p>In the above code the pointer contain the address of derived class object so it should call derived class destructor along with base class destructor when i delete the pointer,but why it is calling only base class destructor. if i made base class destructor as virtual then it is calling both derived class and base class destructor why?. and in virtual functions case both the base and derived class has the same function name so compiler resolve the one which is most derived in the derived class but here the destructor won't have same name then how the compiler resolves which one it has to call during run time.please explain me how</p>