Attaching nodes to a tree in C++ (Reference and pointer help.)
<p>I am writing a balancing binary tree for class, but I am having some confusion as to how to use pointers and references in C++ (coming straight from Java). The code below results in a segfault, because no node has actually been added to the tree, <code>curr</code> has just been switched to the new <code>Node</code>. How would I go about making it so that the new <code>Node</code> goes to where <code>curr</code> is pointing to on the tree, rather than just reassigning <code>curr</code>?</p>

<pre><code>void BalancedTree::insert(int input)
{
    cout &lt;&lt; "Insert started\n"; //DEBUG
    Node* trailingNode;
    Node* curr;

    curr = this-&gt;root;

    while(curr != NULL){
        cout &lt;&lt; "Addloop\n";    //Debug
        if(input &lt; curr-&gt;data){     //input smaller than current
            cout &lt;&lt; "Left\n"; //DEBUG
            trailingNode = curr;
            curr = curr-&gt;left;
        }else{                      //input larger than current node
            cout &lt;&lt; "Right\n"; //DEBUG
            trailingNode = curr;
            curr = curr-&gt;right;
        }
    }   

    insert(curr, input);
    cout &lt;&lt; "test" &lt;&lt; endl; 
    cout &lt;&lt; root-&gt;data &lt;&lt; " added\n";   //DEBUG
//  curr-&gt;parent = trailingNode;    //Set the parent

    size++;                         //Increase size
}

//Helper method
void BalancedTree::insert(Node*&amp; curr, int input)
{
    curr = new Node(input);
}
</code></pre>
