title: c++ less operator overload, which way to use?
body: <p>For example: in a C++ header file, if I defined a <code>struct Record</code> and I would like to use it for possible sorting so that I want to overload the <code>less operator</code>. Here are three ways I noticed in various code. I roughly noticed that: if I'm going to put <code>Record</code> into a <code>std::set</code>, <code>map</code>, <code>priority_queue</code>, … containers, the version 2 works (probably version 3 as well); if I'm going to save <code>Record</code> into a <code>vector&lt;Record&gt; v</code> and then call <code>make_heap(v.begin(), v.end())</code> etc.. then only version 1 works.</p>
  
  <pre><code>  struct Record
    {
        char c;
        int num;
  
        //version 1
        bool operator &lt;(const Record&amp; rhs)
        {
           return this-&gt;num&gt;rhs.num;
        }
  
        //version 2
        friend bool operator &lt;(const Record&amp; lhs, const Record&amp; rhs) //friend claim has to be here
        {
           return lhs-&gt;num&gt;rhs-&gt;num;
        }
    };
  </code></pre>
  
  <p>in the same header file for example:</p>
  
  <pre><code>      //version 3
        inline bool operator &lt;(const Record&amp; lhs, const Record&amp; rhs)
        {
           return lhs-&gt;num&gt;rhs-&gt;num;
        }
  </code></pre>
  
  <p>Basically, I would like to throw the questions here to see if someone could come up with some summary what's the differences among these three methods and what are  the right places for each version?</p>