+ 3
1. The purpose
To define the operation for user defined types.
2. Where do we use it?
Whenever we have our own types, which the built in operators can't handle.
Suppose you have a class User, and there are many objects of that class. The problem here is how do you separate the seniors from the juniors? A nice way would be to check for age, which requires the comparison operators. Without overloading the operator this is not directly possible.
if (userA < userB)
bool User::operator<(const User &aUser) const
{
return this->userAge()<aUser.userAge();
}