A simple meta-accessor rw 6th April, 2009 12:13 (UTC)

I really liked those two articles about accessors but there is one issue that bugs me.

If I'm not mistaken the whole purpose of the Accessors template was to prevent refactoring if it becomes necessary to add some logic to set/get some member variables without explicitly writing those methods. But you can still easily end up with code that would not be allowed with real set/get functions.

For example if you have

class A{

public:

Accessors<int> i;

};

you could do something like

A a, b;

a.i(10);

b.i = a.i; //should not be allowed

Making operator= private would prevent this but A would become not assignable too. Since I'm not very experienced with C++ I failed to come up with a solution, but maybe someone else can enlighten me.