using Unsized Arrays in Structures from d?
NewUser
newuser at newuser.com
Fri May 4 13:27:03 UTC 2018
On Friday, 4 May 2018 at 13:21:53 UTC, Timoses wrote:
> On Friday, 4 May 2018 at 13:02:08 UTC, NewUser wrote:
>> tried defining items[] as both "Item[] items" and "Item*
>> items" in d, it compiles okay but gives an error when trying
>> to access it.
>
> You were on the right track. D array notation is:
>
> <type>[] <identifier>;
>
> For me this works:
>
> ```
> struct Item
> {
> int id;
> };
>
> struct Group
> {
> int i;
> int item_count;
> Item[] items;
> };
>
> void main()
> {
> auto g = Group();
> g.items ~= Item(3);
> assert(g.items[0].id == 3);
> }
> ```
Hi Timoses,
The structure is being returned from c and I'd like use it from d.
What you have work perfectly when assigning from d.
Regards,
NewUser
More information about the Digitalmars-d-learn
mailing list