Error: xxx is not an lvalue
Unknown W. Brackets
unknown at simplemachines.org
Mon May 4 11:53:41 PDT 2009
I've always though of arrays and associative arrays as structs (which
really is what they are.) Thinking that way, this behavior makes exact
sense - down to .length being unchangeable and associative arrays being
unchangeable.
I mean, you wouldn't want to make it work the way you suggest by making
arrays and associative arrays simply pointers to their current structs
(just like a class would be.) You could make such a class easily
yourself, anyway.
If you are right, I guess the right solution would be to make the ref
implicit when returning (or, I suppose, passing?) such arrays and
associative arrays. But that seems wrong to me too, and wouldn't come
free (speaking of efficiency) either.
-[Unknown]
Steven Schveighoffer wrote:
> On Sun, 03 May 2009 05:25:09 -0400, Unknown W. Brackets
> <unknown at simplemachines.org> wrote:
>
>> This code works fine (D 2.x only):
>>
>> class Test
>> {
>> private int[int] _testMap;
>> public ref int[int] testMap() {return _testMap;}
>> }
>>
>> void main()
>> {
>> Test test = new Test();
>> test.testMap[0] = 1;
>> }
>>
>> Note the "ref". Otherwise, a value is returned which is not
>> modifiable. This will also fix test.array.length. Nothing wrong
>> here, no creepy bad temporary property problems.
>
> The original code should work, this is a problem. An AA is not a value
> type.
>
> -Steve
More information about the Digitalmars-d
mailing list