Virtual Destructor

Examples

C++

class Person {
  public:
  ~Person() {
    cout << "Deleting a person." << endl;
  }
};

class Student : public Person {
  public:
  ~Student() {
    cout << "Deleting a student." << endl;
  }
};

int main() {
  Person * p = new Student();
  delete p;
}