I am getting an error using std::find on the following structure …
struct ComplianceOrderRecord {
explicit ComplianceOrderRecord(IOrder& order);
bool operator ==(const ComplianceOrderRecord& other) const;
double price;
};
inline bool ComplianceOrderRecord::operator ==(const ComplianceOrderRecord& other) const {
return price == other.price;
}
I use it as follows…
inline void Compliance::RemoveComplianceOrderRecord(const ComplianceOrderRecord& order) {
auto it = std::find(m_compliantOrderList.begin(),
m_compliantOrderList.end(), order);
if(it == m_compliantOrderList.end()) {
return;
}
m_compliantOrderList.erase(it);
}
The error is…
error C2679: binary '==' : no operator found which takes a right-hand operand of type 'const ComplianceOrderRecord' (or there is no acceptable conversion)
Any help in understanding this error would be very appreciated.
This error can be reproduced if
m_compliantOrderListis not acontainer<ComplianceOrderRecord >. (Perhaps it is a container of pointers, or some other completely unrelated class.Edit:
Your equality operator can compare two instances of
ComplianceOrderRecord, butfindneeds to compare a pointer against an object. Overloading an operator to perform this kind of comparison would be bizarre, so you could usefind_ifwith a custom predicate, such as:or a lambda version thereof.