Okay for my project I had to create a template class for nodes in a linked list. The code:
Code:
template <class T>
class node{
public:
node(){linkfield = NULL;}
node(T d, node *lf){datafield = d; linkfield = lf;}
T data(){return datafield;}
node * link(){return linkfield;}
void setData(T d){datafield = d;}
void setLink(node *lf){linkfield = lf;}
private:
T datafield;
node *linkfield;
};
now I am using this class to make 2 lists, one of a resident object and one of a clothing object (this project is for doing laundry for a household). The problem I am having is in this function which removes an item of clothing from the linked list:
Code:
void Laundry::wearItem(Clothing c){
node <Clothing> * tmp;
if(c_head == NULL) return;
if(c_head->data() == c)
{
tmp = c_head;
c_head = c_head->link();
delete tmp;
}
else
{
tmp = c_head->link();
node <Clothing> * previous = c_head;
while(tmp != NULL && tmp->data() != c){
tmp = tmp->link();
previous = previous->link();
}
if(tmp == NULL)
cout << "That item was not found in the list.\n";
else if(tmp->data() == c)
{
previous->setLink(tmp->link());
delete tmp;
}
}
}
any time i try to compare the data in a node to an object...
Code:
if(c_head->data() == c)
it gives me this error:
no match for 'operator==' in 'node<T>::data() [with T = Clothing]() == c'
it does the same thing in the function i wrote for removing residents. Can anyone help me out with this? I don't see why this should be happening since the template class should be returning whatever type of object that is being used in it, then comparing it. sorry if this is unclear but any help would be much appreciated
-alex