I'm trying to write an overloaded assignment operator for my linked list class using a template but I keep getting errors.
Any help with what I'm doing wrong would be great.
The error I'm getting is "out of line definition does not match any declaration in LL".
The declaration I have is:
const LL<T>& operator=(const LL<T> &rhsObj);
and the implementation is:
template<typename T>
LL<T>& LL<T>::operator=(const LL<T>& rhsObj) const
{
if (this!= &rhsObj)
{
//no self assignment so OK to continue
//deallocate left hand side memory
this->clear();
count = 0;
head = NULL;
cout <<"calling function copyList()" << endl;
count = 0;
head = NULL;
string diCode = "";
int onNode = 0;
if(rhsObj.head == NULL)
{
cout <<"other list is empty, nothing to do" << endl;
}
else
{
onNode =0;
Node<T> *otherCurrent = rhsObj.head;
while( otherCurrent != NULL)
{
int duplicateInfo;
duplicateInfo = otherCurrent->info;
push_back(duplicateInfo);
otherCurrent = otherCurrent ->next;
onNode++;
} //END while(otherCurrent != NULL)
} // END else block of if (otherLL.head == NULL)
} // END if (this != &rhsObj)
return *this;
}