On 3/3/23 12:45, Joe wrote:
> I had tried changing B.x1() to:
>
>`ref X x1() { return &xs[0]; }`
>
> but the compiler didn't accept it.
Yeah, that wouldn't work because the return expression is an X*.
Even though 'ref' is implemented as a pointer behind the scenes, that
syntax is not legal
Thanks, Ali.
On Friday, 3 March 2023 at 18:09:01 UTC, Ali Çehreli wrote:
Think may be due to D not having reference variables. Sometimes
one needs to use pointers.
Ah! I'm about five chapters away from Pointers ;-).
Actually, I had tried changing B.x1() to:
`ref X x1() { return &xs[0]; }`
On 3/3/23 06:03, Joe wrote:
> My understanding was that since A, B and X[] are all reference types,
> this ought to work, but obviously something is missing.
Think may be due to D not having reference variables. Sometimes one
needs to use pointers.
I find the following a simpler (and complete
Let's say we have two classes, A and B. The latter has a dynamic
array of X and type X has an add() method that can be used to
append elements (of type C, another struct) to X's own dynamic
array of C. So it's something like the following:
```d
struct C {}
struct X { C[] cs;
void add(C c)