1
votes

I am overloading the assignment operator, and am getting this error. Cannot solve it.

Here is the prototype inside template class binTree

binTree <T>& operator = ( const binTree <T>& ); // assignment operator

Here is the method

// assignment operator
template <class T>
void binTree <T>::binTree <T>& operator = ( const binTree <T>& p)
{
    if( this != &p ) 
    { 
        clear(root); // clear tree 
        root = copy(p.root); // copy tree
    }      
    return *this;
}

I am getting the error on this line

void binTree <T>::binTree <T>& operator = ( const binTree <T>& p)
2

2 Answers

4
votes

From your declaration

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

Your class type is

binTree<T>::

your member is

operator =(const BinTree<T>& p)  

Your return type is

binTree<T>&

So your definition is

binTree<T>& binTree<T>::operator= (const binTree<T>& p){
     // bug-free code goes here
}
0
votes

You do not need the second bintree<T> in the return type

binTree <T>& operator = ( const binTree <T>& p)

EDIT: removed void from beginning of line (the result of too fast copy-paste)