// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
#include <iostream>

using namespace std;

class BadParent
{
    public:
        ~BadParent();
};

class BadChild : public BadParent
{
    public:
        ~BadChild();
};

BadParent::~BadParent()
{
    cout << "BadParent dtor called" << endl;
}

BadChild::~BadChild()
{
    cout << "BadChild dtor called" << endl;
}

class GoodParent
{
    public:
        virtual ~GoodParent();
};

class GoodChild : public GoodParent
{
    public:
        virtual ~GoodChild();
};

GoodParent::~GoodParent()
{
    cout << "GoodParent dtor called" << endl;
}

GoodChild::~GoodChild()
{
    cout << "GoodChild dtor called" << endl;
}

int main()
{
    cout << "BadP = BadP" << endl;
    BadParent *o1 = new BadParent();
    delete o1;
    cout << "BadC = BadC" << endl;
    BadChild *o2 = new BadChild();
    delete o2;
    cout << "BadP = BadC" << endl;
    BadParent *o3 = new BadChild();
    delete o3;
    cout << "GoodP = GoodP" << endl;
    GoodParent *o4 = new GoodParent();
    delete o4;
    cout << "GoodC = GoodC" << endl;
    GoodChild *o5 = new GoodChild();
    delete o5;
    cout << "GoodP = GoodC" << endl;
    GoodParent *o6 = new GoodChild();
    delete o6;
    return 0;
}
