idiomatic D: what to use instead of pointers in constructing a tree data structure?
Laeeth Isharc via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jan 13 09:19:40 PST 2015
On Wednesday, 7 January 2015 at 14:59:58 UTC, H. S. Teoh via
Digitalmars-d-learn wrote:
> On Wed, Jan 07, 2015 at 02:52:51PM +0000, Laeeth Isharc via
> Digitalmars-d-learn wrote:
>> Another schoolboy question.
>>
>> Suppose I am constructing a tree (in this case it is an AST).
>> In C I
>> would have a pointer for the child to find the parent, and an
>> array or
>> linked list of pointers to find the children from the parent.
>>
>> Obviously, I could still use pointers, but that would not be
>> idiomatic.
>
> Not true. If you're using a tree structure, you *should* use
> pointers.
> Unless you're using classes, which are by-reference, in which
> case you
> can just use the class as-is. :-)
>
>
> --T
The GC is allowed to move structs around, as I undestand it.
Under what circumstances do I get into trouble having a pointer
to them?
More information about the Digitalmars-d-learn
mailing list