compiler error
What does this compiler error mean?
error: expected constructor, destructor, or type conversion before '&' token
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
/****************************************************************************
Function: operator=
Use: overload the operator =
Arguements: A const reference to BSTree template type
Returns: *this
****************************************************************************/
template <class T>
BT<T>::BT& operator=(const BT<T>& otherTree)
{
if (this != &otherTree) //avoid self-assignment
{
if (root != NULL) //if binary tree isnt empty, destroy tree
destroy_tree(root);
if(otherTree.root == NULL) //other tree is empty
root = NULL;
else
copyTree(root, otherTree.root);
}
return *this;
}
|
I'm not sure, but shouldn't it be:
BT<T>& BT<T>::operator = (const BT<T>& otherTree )
?
Hope this helps.
That was right!
Thank you
Maybe someone can hep me with another question! The normal way i know how to do a binary tree traversal is to do it like this
1 2 3 4 5 6 7 8 9 10
|
void BT<T>::inOrder(BSTNode<T> *p) const
{
if (p != NULL)
{
inOrder(p->left);
cout << p->data << " ";
inOrder(p->right);
}
}
|
However my instructor has an extra parameter and i dont know what its for. She doesnt have office hours till thursday, could anyone help explain this.
inOrder(Node<T>*, void (*)(T&));
It is a pointer to a function to call on the node.
(Note that your code does a cout on each node (2nd line). Her code instead calls the function passed in.
Topic archived. No new replies allowed.