Currently I am studying Standard Template Library (STL).
In this program I am storing some long values in Associative Container and then sorting them according to unit's place (according to the number in unit's place).
Code :
#include <iostream>
#include <set>
#include <functional>
using namespace std;
class UnitLess
{
public:
bool operator()(long first, long second)
{
long fu = first % 10;
long su = second % 10;
return fu < su;
}
};
typedef set<long, UnitLess> Ctnr;
int main(void)
{
Ctnr store;
store.insert(3124);
store.insert(5236);
store.insert(2347);
store.insert(6415);
store.insert(4548);
store.insert(6415);
for(Ctnr::iterator i = store.begin(); i != store.end(); ++i)
{
cout << *i << endl;
}
}
But I don't understand why our Professor has overloaded () operator ?
Thanks.