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:
It means it can’t find any
==operator that accepts anentrytype as its left operand. This code isn’t valid: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
entrytype, whatever that is. Either give the class anoperator==function, or declare a standaloneoperator==function that accepts aconst entry&as its first parameter.I think the latter is the preferred style.