operator()()
is what I would call the "function operator". It makes the object behave like a function would, in the sense that I can use the same syntax as a function if I overload it:
class foo {
bool operator()() {
//...
}
// ...
};
// later...
bool myBool = myFoo();
As you can see, it acts like a function would.
operator<()
, on the other hand, is a comparison operator. It allows me to use my foo in a comparison context, most commonly in if statements:
class foo {
bool operator<(const foo& otherFoo) const {
//...
}
// ...
};
// later...
if(myFoo1 < myFoo2) {
//...
}
Edit:
I tried replacing < with () but it threw an error
Without knowing the context you are trying to use them in, it's hard to answer why, but it's good to know that these two not only aren't the same, but are usually used in very different contexts. You can't just change the <
to a ()
and expect it to work. C++ doesn't work that way. You need to change the context the operators are used in, not just what operator your class has overloaded.