Overloading comparison operators for use in a Set

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
bool operator<(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&)
Last edited on
if they are equal, your implementation of > will return true.
@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.
I still need help.
Take const references.
@LB, Wow. That was all it needed. Thank you very much!
Topic archived. No new replies allowed.