I'm doing (something like) this:
void insert(Node*& node, string val, Node* parent)
{
if (node == NULL)
instantiateNode(node, val, parent);
else
insert(node->child, val, node);
}
The thing is, that instantiateNode(..., parent)
seems to modify the original *&node
passed into the function when setting the *parent
. instantiateNode()
is supposed to alter the node
, but if it alters the parent
than you have a node that is set to its parent, which doesn't make sense, and also doesn't work. At all.
The reason I'm bothering with pointer references at all is because it eliminates special cases and significantly reduces the amount of error checking I have to do. Since I'm doing it to reduce line count and trivial algorithm-ish duplication, I can get around this by approximately doubling the code line count. But I'd rather not, and I feel like there should be a way to dereference a pointer reference to get a new pointer that points to the same object. And, really, I thought that pass of *&node
through *parent
should have done it, but apparently gcc is optimizing it out.