Reputation:
I'm having some trouble implementing a search function for a Linked List using base code from this data structures book. This is the error I'm getting:
llist.h: In member function 'void LList<E>::search(const E&, bool&) [with E = Int]':
Llistmain.cpp:31:1: instantiated from here
llist.h:119:3: error: no match for 'operator==' in '((LList<Int>*)this)->LList<Int>::curr->Link<Int>::element == value'
And here is the implementation of my search member function:
void search(const E& value, bool& found) {
if (curr->element == value)
found = true;
else if (curr != NULL) {
curr = curr->next;
search(value, found);
}
else found = false;
}
Why am I getting an error about the == operator
? Both curr->element
and value
are of type Int. Should I be checking for equality differently?
Upvotes: 1
Views: 130
Reputation: 153840
Does your type Int
have a comparision operator? If it has, does it take both of its arguments as const
? In particular, if you comparision operator is a member it is easy to forget to make it a const
member:
bool Int::operator== (Int const& other) const {
...
}
Upvotes: 1
Reputation: 75130
According to the error, element
is not an int
but a Link<Int>
. You need to get the Int
out of the Link
and turn it into something that has an operator==
(note that Int
is not int
).
Upvotes: 0