This is the problem I have. I have an class hierarchy like java's with an object base class named Object.
There is also a class named Reference that contains a pointer to a Object. It is like
class Reference{
public:
Object *value;
....
};
Two or more references can point to the same object but how can I make that when a Reference that shares
the object wiht some other reference changes the value of the object, it can be viewed by all the other
references?
I've tried somethig like:
Reference *a = new reference();
Reference *b = new reference();
a->value = some object
b->value = a->value; // a and b point to the same object, the have the same address
// some change to a's value
object *o = some object
*(a->value) = *o; // both a and b values remains unchanged
What I want to do is some kind of aliasing simulation, but without using the one provided by C++.
Two or more references can point to the same object but how can I make that when a Reference that shares
the object wiht some other reference changes the value of the object, it can be viewed by all the other
references?
I've tried somethig like:
Reference *a = new reference();
Reference *b = new reference();
a->value = some object
b->value = a->value; // a and b point to the same object, the have the same address
That works. When the value of the object changes, both reference objects (a and b) see the changed object. You've presented a working solution to your own question.