title: How to pass a comparator as a parameter for a function?
body: <p>I have a function in a sorting header for mergeSort </p>
  
  <p>This is my code:</p>
  
  <p>template </p>
  
  <pre><code>void mergeSort(vector&lt;Comparable&gt; &amp; a, vector&lt;Comparable&gt; &amp; tmpArray, int left int right, Comparator cmp)
  {
      if (cmp(left,right))
      {
          int center = (left + right) / 2;
          mergeSort(a, tmpArray, left, center);
          mergeSort(a, tmpArray, center + 1, right);
          merge(a, tmpArray, left, center + 1, right);
      }
  }
  </code></pre>
  
  <p>I want to use this comparator and pass in the parameters in my mainDriver.cpp</p>
  
  <pre><code>class CompareXCoordinate {
  public:
      bool operator()(const Point &amp; p1, const Point &amp; p2) const
      {
          return (p1.getX() &lt; p2.getX());
      }
  };
  </code></pre>
  
  <p>Currently I am passing it like this:</p>
  
  <p>Points is vector of Point objects
  tempArr is an empty vector</p>
  
  <pre><code>mergeSort(points, tempArr, points.begin(), points.end(), Point::CompareXCoordinate::operator())
  </code></pre>
  
  <p>I get an error of C3867: non-standard syntax, use &amp; to create pointer to member</p>
  
  <p>Is that the proper way to pass a comparator or is it a different syntax?</p>