// 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 Data
{
private:
    int v;
public:
    void SetV(int v);
    int GetV();
};

void Data::SetV(int v)
{
    cout << "SetV called" << endl;
    this->v = v;
}

int Data::GetV()
{
    return this->v;
}

// ****
template<int Data::*ptr>
struct Steal
{
    friend void hack(Data& o, int v)
    {
        o.*ptr = v;
    }
};

template class Steal<&Data::v>;

void hack(Data& o, int v);
// ****

int main()
{
    Data o;
    o.SetV(123);
    cout << o.GetV() << endl;
    // error:
    // o.v = 456;
    // no error:
    hack(o, 456);
    cout << o.GetV() << endl;
    return 0;
}
    
