Hello all. Strange thing happening and I am at my wit's end. Sorry for the lump of code but it's meant to generate a simple tree. As you can see from the output, somewhere the parent pointers get messed up. And yet, I can't seem to find where, and if I output them in the constructor (only time they get modified) they all look OK. When I run output_path_to_root() on any grandchildren of the root I get a segmentation fault. Any ideas on how the parents are getting messed up? I was wondering if my vectors changing size is causing pointers to shift around but I'm not sure that makes sense or how I would fix it. Thanks.
Figured it out. The short answer is the children vector should be of pointers to dynamically allocated instances instead of a vector of objects because otherwise they go out of scope.
The long answer is that actually the objects don't go out of scope because they are all copied around into new vectors. That's actually the problem, though. When I push an object into a vector, it gets copied to a new address in memory. That means all its children don't know where their parent is anymore because its address changed and the old one (that they were pointed towards) went out of scope. Hence the parent pointers being nonsense.
I'm glad I figured it out because that is a really tough bug to work out... Hopefully this will help someone else.