Hello, I have a small piece of code that used the set::insert function on a set of myClass. For that, I need to overload the < and > operators, which I have, but I still get a huge error saying it can't compare.
1 2
set<MyClass> mySet;
MyClass myClass
All the class information gets filled in. Then, I try to insert... mySet.insert(myClass);
1 2 3 4
booloperator<(MyClass &lhs, MyClass &rhs)
{
return lhs.name < rhs.name; //name is a string
}
The error says
...stl_function.h:230:22: error: no match for 'operator<' in '__x < __y'
MyFile.h:80:6: note: candidate is bool operator<(MyClass&, MyClass&)
@Esslercuffi, I took out the > operator since the set::insert only uses <.
It should just iterate through the set until it finds the spot where lhs < rhs, then insert it there.