Thread overview | |||||
---|---|---|---|---|---|
|
August 23, 2014 Acces Values in DList | ||||
---|---|---|---|---|
| ||||
How can i access values in DList? I save different objects of type "Property" in my DList, but if i want to access them this way: this.properties[0].value.start i get: Error: no [] operator overload for type DList!(Property) |
August 23, 2014 Re: Acces Values in DList | ||||
---|---|---|---|---|
| ||||
Posted in reply to axwro | On Saturday, 23 August 2014 at 14:54:55 UTC, axwro wrote:
> How can i access values in DList?
>
> I save different objects of type "Property" in my DList, but if i want to access them this way:
>
> this.properties[0].value.start
>
> i get:
>
> Error: no [] operator overload for type DList!(Property)
Fixed, i just used Array!Property
|
August 23, 2014 Re: Acces Values in DList | ||||
---|---|---|---|---|
| ||||
Posted in reply to axwro | On Saturday, 23 August 2014 at 15:18:15 UTC, axwro wrote:
> On Saturday, 23 August 2014 at 14:54:55 UTC, axwro wrote:
>> How can i access values in DList?
>>
>> I save different objects of type "Property" in my DList, but if i want to access them this way:
>>
>> this.properties[0].value.start
>>
>> i get:
>>
>> Error: no [] operator overload for type DList!(Property)
>
>
> Fixed, i just used Array!Property
DList implements what is known as a "(doubly) linked list". It is a container type that is not capable of providing random acess. As such, you cannot do "properties[0]". You can either access the first ("front") value individually, or iterate your DList (via its range interface "foreach(val; this.properties[]) {...}").
Array implements a basic contiguous sequence of elements (hence provides RA).
It is important you understand what you are using, and which container best fits your needs.
|
Copyright © 1999-2021 by the D Language Foundation