I'm trying to make a tree data structure in part of my first non-trivial D-based program. Turns out that DMD likes to re-use PODs - sounds good, but that trapped me, and I'm not sure how to clear myself out of the problem nicely.

My simplified, but not oversimplified, example is http://dpaste.dzfl.pl/67b022ca029e

You'll note in the output of the program several duplicated values for "self" and the parent value goes to places other than the parent. This is all wrong, and shows my ignorance, but is as far as I've been able to work it.

In my operational code I bypassed the problem by storing every leaf and branch in an array and changing the self, parent, and children properties to be indices into said array. But this feels hackish: I'd rather have the tree itself hold everything it needs.

Note: I'm not stuck with a struct. I could class the thing, but I figured that a struct holds what I need simply...

Thoughts, solutions?

Reply via email to