At first I thought that the purpose of the 'aref' data type was to provide a reference to an object's attribute with all the functionality of a traditional reference. But to my surprise I found that assignments to these references had no effect!
It's not possible to use the assignment operator in combination with the reference operator for object attributes:
This seems to be what makearef() is for.
But here's the interesting part. You can't assign a value to an attribute using an attribute reference. What's even more bizarre is that attempting to do so results in an error "Invalid conversation".
My question here is whether this kind of behavior is guaranteed. Is there any way to assign a value to an attribute using a reference to it or is this impossible?
It's not possible to use the assignment operator in combination with the reference operator for object attributes:
Code:
object table;
table.num = 123;
// Can't assign a reference to an attribute
aref arNum = &table.num; // error.log: AClass ERROR n1
This seems to be what makearef() is for.
Code:
object table;
table.num = 123;
aref arNum; makearef(arNum, table.num);
table.num = 456;
trace(arNum); // Outputs 456
But here's the interesting part. You can't assign a value to an attribute using an attribute reference. What's even more bizarre is that attempting to do so results in an error "Invalid conversation".
Code:
object table;
table.num = 123;
aref arNum; makearef(arNum, table.num);
table.num = 456;
// Can't assign value to aref?
arNum = 789; // error.log: Invalid conversation
trace(arNum); // Outputs 456
My question here is whether this kind of behavior is guaranteed. Is there any way to assign a value to an attribute using a reference to it or is this impossible?
Last edited: