title: Different ways of using a comparator in C++
body: <p>I saw two different answers in Leetcode using comparators:</p>
  <ol>
  <li><p>why is the first <code>Comp</code> function defined outside of the class? Even when I bring <code>Comp</code> into the class, the Leetcode fails.</p>
  </li>
  <li><p>How are you able to use <code>Comp</code> with out the <code>()</code>?</p>
  </li>
  <li><p>How come I often see compare in structs?</p>
  </li>
  </ol>
  <pre><code>bool Comp(const string&amp; a, const string&amp; b) {
      ...
  }
  
  class Solution {
  public:
      vector&lt;string&gt; reorderLogFiles(vector&lt;string&gt;&amp; logs) {
          stable_sort(logs.begin(), logs.end(), Comp);
          // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ here
          return logs;
      }
  };
  </code></pre>
  <p>and then</p>
  <pre><code>struct CompareLogs
  {
      bool operator() (const string&amp; str1, const string&amp; str2)
      {
          ...
      }
  };
  
  vector&lt;string&gt; reorderLogFiles(vector&lt;string&gt;&amp; logs) {
      sort(letter_logs.begin(), letter_logs.end(), CompareLogs());
      // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ and here       
      return letter_logs;
  }
  </code></pre>