
Originally Posted by
georgi0u
Anyway im posting this for future referance because i already figured it out. The problem was with the way i was dealing with node parents...
You still didn't code an assignment operator. If not, your program will not be able to do this correctly:
Code:
int main()
{
TreeNode<int> T1;
TreeNode<int> T2;
T1 = T2; // no good
}
When coding a copy constructor, it always goes with an assignment operator. The reason why is that C++ programmers who expect this to work:
Code:
TreeNode<int> T1;
TreeNode<int> T2 = T1; // copy constructor called
Also expect this to work:
Code:
TreeNode<int> T1;
TreeNode<int> T2;
T1 = T2;
since both are natural means of assigning and constructing objects.
Regards,
Paul McKenzie