cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : Beginners : compiler error
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programm...
Articles
Lounge
Jobs

-

post  compiler error

bluegray (34)
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;
}
|
Duoas (1595)
I'm not sure, but shouldn't it be:
BT<T>& BT<T>::operator = (const BT<T>& otherTree )
?

Hope this helps.
|
bluegray (34)
That was right!
Thank you
|
bluegray (34)
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&));
|
jsmith (958)
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.
|

This topic is archived - New replies not allowed.
Home page | Privacy policy
© cplusplus.com, 2000-2009 - All rights reserved - v2.2
Spotted an error? contact us