[Dev-C++] Errors in compiling an Assignment Operator
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Socha, D. F <dav...@us...> - 2003-06-09 17:09:10
|
Me again,
=20
The error that is throwing me off is the error on line 519 where it =
states that there is a syntax error before the '&' token. That line is =
the line that contains "template<typename T> BST& BST<T>::operator=3D =
(const BST& origTree){".
I also don't understand why the compiler is giving me these errors:
bst.h:519: ISO C++ forbids declaration of `operator=3D' with no type
bst.h:519: `int& operator=3D(...)' must be a nonstatic member function
bst.h:519: `int& operator=3D(...)' must take exactly two arguments
I am using Dev C++ 4.9.8.0
Here is a copy of my compile log as well as copies of the code for the =
functions in question=20
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\code\bst\Makefile.win"
Finding dependencies for file: C:\Dev-Cpp\code\bst\bstTester.cpp
Executing make...
make.exe -f "C:\Dev-Cpp\code\bst\Makefile.win" all
g++.exe -c bstTester.cpp -o bstTester.o -I"C:/Dev-Cpp/include/c++" =
-I"C:/Dev-Cpp/include/c++/mingw32" -I"C:/Dev-Cpp/include/c++/backward" =
-I"C:/Dev-Cpp/include" =20
In file included from bstTester.cpp:13:
bst.h:519: syntax error before `&' token
bst.h:519: `T' was not declared in this scope
bst.h:519: template argument 1 is invalid
bst.h:519: parse error before `&' token
bst.h:519: ISO C++ forbids declaration of `operator=3D' with no type
bst.h:519: `int& operator=3D(...)' must be a nonstatic member function
bst.h:519: `int& operator=3D(...)' must take exactly two arguments
bst.h: In function `int& operator=3D(...)':
bst.h:520: `root' undeclared (first use this function)
bst.h:520: (Each undeclared identifier is reported only once for each =
function=20
it appears in.)
bst.h:520: `origTree' undeclared (first use this function)
bst.h:523: `destroyTree' undeclared (first use this function)
bst.h:526: `orig' undeclared (first use this function)
bst.h:527: `copyTree' undeclared (first use this function)
bst.h:534: invalid use of `this' in non-member function
make.exe: *** [bstTester.o] Error 1
Execution terminated
=20
=20
/************************************************************************=
****
copyTree function
Used by the copy constructor / asignment operator to copy the tree
=20
Sent: pointer to the original node, pointer to the node being copied to
Returns: Nothing
=20
Works by: Creating a new node on the tree being copied, copy the data to =
the
node, checks to see if a left node exists on the tree, if yes
repeat the process using on the left node, if not, do nothing. Then =
checks
the right, if it exists repeat process on the right side, if not, do =
nothing
=20
NOTE: This function is a recursive process
*************************************************************************=
***/
=20
template<typename T> void BST<T>::copyTree(Node* origNode, Node* =
copyNode){
copyNode =3D new Node(origNode->data);
=20
if(origNode->left){
copyTree(origNode->left, copyNode->left);
}
=20
if(origNode->right){
copyTree(origNode->right, copyNode->right);
}
}
//End copyTree
=20
=20
/************************************************************************=
****
Overloaded assignment operator
Used for: assigning the value of one tree to another tree
=20
Sent: A reference to the original tree
Returns: A reference to a tree
=20
Works by: First checking to see if the tree being copyied to has data in =
it.
If it does, the deleteTree function is called to empty the tree/free up =
all the
memory in the tree.
Second, checks to see if the tree being copyied has any data in it. =
If it
does, the copyTree function is called to copy the data from the original =
tree to
the copy tree. If the original tree does not have data on it (root =
=3D=3D NULL)
then the root of the copy tree will be set to null.
*************************************************************************=
***/
=20
=20
template<typename T> BST& BST<T>::operator=3D (const BST& origTree){
if (root !=3D origTree.root){
=20
if(root){
destroyTree(root);
}
=20
if(orig.root){
copyTree(origTree.root, root);
}
else{
root=3DNULL;
}
}
=20
return *this;
}
//End operator=3D
Thanks for all of the help
David Socha
|