How to write a comparison operator in c++?
<p>I'm having an array of structure containing three fields:</p>

<pre><code>struct data{
   int s;
   int f;
   int w;   
};

struct data a[n];
</code></pre>

<p>In order to sort the array of structure based on field f I'm using my own comparison operator :</p>

<pre><code>bool myf( struct data d1,const struct data d2){
   return d1.f &lt; d2.f ; 
}
</code></pre>

<p>The above operator works fine in inbuilt <code>sort()</code> function :</p>

<pre><code> sort(a,a+n,myf);
</code></pre>

<p>but it's not working for <code>upper_bound()</code> function :</p>

<pre><code> upper_bound(a,a+n,someValue,myf); 
</code></pre>

<p>Can anyone tell me where am I doing wrong ? Is my comparison operator wrong ? If it's wrong, why is it working for <code>sort() function and not upper_bound()</code> ?</p>

<p>I'm getting following on compilation :</p>

<pre><code>    /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_algo.h: In function     ‘_FIter std::upper_bound(_FIter, _FIter, const _Tp&amp;, _Compare) [with _FIter = data*, _Tp =     int, _Compare = bool (*)(data, data)]’:
   prog.cpp:37:   instantiated from here

    /usr/lib/gcc/i686-pc-linux-gnu/4.3.4/include/g++-v4/bits/stl_algo.h:2243: error: conversion from ‘const int’ to non-scalar type ‘data’ requested
</code></pre>
