using Unsized Arrays in Structures from d?
Timoses
timosesu at gmail.com
Fri May 4 13:21:53 UTC 2018
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);
}
```
More information about the Digitalmars-d-learn
mailing list