Properties and std.container.Array

Frustrated c1514843 at drdrb.com
Thu Jan 9 04:19:24 PST 2014


On Thursday, 9 January 2014 at 12:15:31 UTC, Frustrated wrote:
> On Thursday, 9 January 2014 at 12:13:14 UTC, Frustrated wrote:
>> I've tried insert, indexing, ~=, etc but the length always 
>> returns 0.
>>
>> e.g.,
>>
>> std.container.Array!int arr;
>> arr ~= 3;
>> writeln(arr.length);
>>
>> works fine, but when the array is a property of a class, it 
>> does not work, e.g.,
>>
>> class x
>> {
>> std.container.Array!int _arr;
>> @property std.container.Array!int arr() { return _arr; }
>> @property std.container.Array!int arr(std.container.Array!int 
>> a) {_arr = a; return _arr; }
>> }
>>
>> if I use _arr directly then everything works.
>>
>> Why are properties screwing up std.container.Array?
>
> I should also mention that if I simply assign the arr property 
> to a local variable before I use it everything works but this 
> is not the way things should work.

I guess I see what is going on. Since Array is a struct, a local 
copy is made and that never ends up updating the original?

How can I use it then like an object so this is not a problem?




More information about the Digitalmars-d-learn mailing list