Array of pointers

Philippe Sigaud philippe.sigaud at gmail.com
Thu Jan 16 12:12:28 PST 2014


On Thu, Jan 16, 2014 at 10:47 AM, Rene Zwanenburg
<renezwanenburg at gmail.com> wrote:

> Keep in mind that, unlike in c++, D classes are reference types:
>
> class Node
> {
>     Node[] nodes; // This is valid
> }
>
> Structs are value types though, so using a struct in the above example is
> illegal.

That's not true. Indeed:

`struct Node { T value; Node[] children;}`

is my standard way of having trees in D.

The thing is, an array is a reference type and so the compiler is able
to determine `Node` size (T.sizeof + a pointer size, or maybe 2, I
don't remember which).


More information about the Digitalmars-d-learn mailing list