Overload Sort

struct integer {
  int val;
  integer(int x): val(x) {}
};
struct compare1 {
  bool operator() (integer a, integer b ) { return a.val < b.val; }
};
struct compare2 {
  bool operator() (integer a, integer b ) { return a.val < b.val; }
}comp;

bool compare3 (integer a, integer b ) { return a.val < b.val; }
int main() {
  integer a(1), b(2);
  vector<integer> tmp;
  tmp.push_back(a);
  tmp.push_back(b);
  sort(tmp.begin(), tmp.end(), compare1());
  sort(tmp.begin(), tmp.end(), comp);
  sort(tmp.begin(), tmp.end(), compare3);
  return 0;
}

results matching ""

    No results matching ""