// File: ex7-14.cpp - Why a Virtual destructor?  Here's why!

#include <iostream>
using namespace std;

class Base
{
public:
    Base()
    {
        cout << "Base constructor called\n";
    }
    virtual ~Base()
    {
        cout << "Base destructor called\n";
    }
};


class Derived : public Base
{
public:
    Derived()
    {
        cout << "Derived constructor called\n";
    }
    ~Derived()
    {
        cout << "Derived destructor called\n";
    }
};


int main()
{
    Base* ptrBase;

    ptrBase = new Base;
    delete ptrBase;

    cout << endl;

    ptrBase = new Derived;
    delete ptrBase;
}