// 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 C
{
    private:
        int v;
    public:
        C() { v = 0; }
        void P() const { cout << v << endl; }
        void A() { v++; } // compiler error to declare this method as const
};

void Test1(C *o)
{
    o->P();
    o->A();
    o->P();
}

void Test2(const C *o)
{
    o->P();
    //compiler error due to const: o->A();
    o->P();
}

void Test3(C *const o)
{
    //compiler error due to const: o = new C();
    o->P();
    o->A();
    o->P();
}

void Test4(const C *const o)
{
    //compiler error due to const: o = new C();
    o->P();
    //compiler error due to const: o->A();
    o->P();
}

int main()
{
    C *o = new C();
    Test1(o);
    Test2(o);
    Test3(o);
    Test4(o);
    return 0;
}
