954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Problems with overload operator method

Hi all. I am having a hard time trying to properly declare a header for my assignment overload operator function.

My prototype for the function is:

const BSTree<T>& operator=(const BSTree<T>&);


And my attempt to write the header for the method is as follows:

template <class T>
const BSTree<T> BSTree<T>::operator=(const BSTree<T> & copyRoot)
{
return copyRoot;
}


Obviously it doesnt do anything inside the method, but my main aim is to get the program to compile without errors, then i will concentrate on the body of the method. The errors i get when trying to compile make me confused, so i was hoping if i give them, someone can help me out ...

here are the errors:
80 BSTree.h prototype for `const BSTree BSTree::operator=(const BSTree&)' does not match any in class `BSTree'
75 assign8\BSTree.h const BSTree& BSTree::operator=(const BSTree&)
80 assign8\BSTree.h template definition of non-template `const BSTree BSTree::operator=(const BSTree&)'

Hope these errors make sense to someone else... any help would be greatly appreciated as always.

Thank you folks

tones1986
Junior Poster
179 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 

You are missing a & in the definition. The return type in the declaration is

const BSTree&

but in the definition its

const BSTree

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

Great - thank you for your help.

tones1986
Junior Poster
179 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You