Error:
error C2678: binary '==' : no operator found which takes a left-hand operand of type 'const entry' (or there is no acceptable conversion)
The function:
template <class T, int maxSize>
int indexList<T, maxSize>::search(const T& target) const
{
for (int i = 0; i < maxSize; i++)
if (elements[i] == target) //ERROR???
return i; // target found at position i
// target not found
return -1;
}
Is this suppose to be an overloaded operator? Being a template class I am not sure I understand the error?
Solution- The overload function in the class now declared const:
//Operators
bool entry::operator == (const entry& dE) const <--
{
return (name ==dE.name);
}
Start by reading the error text exactly as it is:
binary '==' : no operator found which takes a left-hand operand of type 'const entry'
It means it can't find any ==
operator that accepts an entry
type as its left operand. This code isn't valid:
entry const e;
if (e == foo)
You've showed us the code for your list class, but that's not what the error is about. The error is about a lack of operators for the entry
type, whatever that is. Either give the class an operator==
function, or declare a standalone operator==
function that accepts a const entry&
as its first parameter.
struct entry {
bool operator==(const entry& other) const;
};
// or
bool operator==(const entry& lhs, const entry& rhs);
I think the latter is the preferred style.