Get pointer or reference of an element in Array(struct)

Azi Hassan azi.hassan at live.fr
Sat Dec 9 23:27:59 UTC 2017


On Saturday, 9 December 2017 at 06:46:27 UTC, Arun Chandrasekaran 
wrote:
> On Saturday, 9 December 2017 at 06:38:46 UTC, anonymous wrote:
>> On Saturday, 9 December 2017 at 06:15:16 UTC, Arun 
>> Chandrasekaran wrote:
>>> Is there a way to get the pointer or reference of an element 
>>> in Array(T)?
>> [...]
>>>     auto d2 = gallery[0];
>>
>> auto d2 = &gallery[0];
>
> Thanks. Just curious why reference can't be obtained here. 
> Saves nasty null checks in most places.

In D, structs are passed by value unless otherwise specified. 
Using a class will yield the expected result.


More information about the Digitalmars-d-learn mailing list