// 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>
#include <vector>

using namespace std;

class P
{
    protected:
        int vp;
    public:
        P(int vp) { this->vp = vp; }
        virtual void print() { cout << "P val: " << vp << " (@" << (int)this << ")" << endl; }
        P(const P& o) { this->vp = o.vp; cout << "P copy: " << (int)&o << "->" << (int)this << endl; }
};

class C : public P
{
    protected:
        int vc;
    public:
        C(int vp, int vc) : P(vp) { this->vc = vc; }
        virtual void print() { cout << "C val: " << vp << " " << vc << " (@" << (int)this << ")" << endl; }
        C(const C& o) : P(o) { this->vc = o.vc; cout << "C copy: " << (int)&o << "->" << (int)this << endl; }
};

int main()
{
    cout << "create P" << endl;
    P op(123);
    cout << "print P" << endl;
    op.print();
    cout << "create C" << endl;
    C oc(456, 789);
    cout << "print C" << endl;
    oc.print();
    vector<P> v;
    cout << "save P in vector" << endl;
    v.push_back(op);
    cout << "save C in vector" << endl;
    v.push_back(oc);
    cout << "print vector" << endl;
    v[0].print();
    cout << "print vector" << endl;
    v[1].print();
    return 0;
}
