title: How to use make_heap to create a min heap in c++
body: <p>How do I create a a min heap using the <code>make_heap</code> method in <code>&lt;algorithm&gt;</code></p>
  
  <p>From the <a href="http://www.cplusplus.com/reference/algorithm/make_heap/" rel="nofollow noreferrer">documentation</a> it says, we can pass in a third argument <strong>Compare comp</strong> that is a</p>
  
  <blockquote>
    <p>Binary function that accepts two elements in the range as arguments,
    and returns a value convertible to bool. The value returned indicates
    whether the element passed as first argument is considered to be less
    than the second in the specific strict weak ordering it defines. The
    function shall not modify any of its arguments. This can either be a
    function pointer or a function object.</p>
  </blockquote>
  
  <p>So I tried passing in a <em>function object</em> as follows</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;utility&gt;
  #include &lt;algorithm&gt;
  
  using namespace std;
  
  struct myComp {
  
      bool operator() (const pair&lt;int, char&gt;&amp; lhs, const pair&lt;int, char&gt;&amp; rhs) {
          return lhs.first &gt; rhs.first;
      }
  };
  
  int main() {
      vector&lt; pair&lt;int, char&gt; &gt; Q;
      Q.push_back( pair&lt;int, char&gt;(10, 'c') );
      Q.push_back( pair&lt;int, char&gt;(123, 'a') );
      Q.push_back( pair&lt;int, char&gt;(2, 'd') );
      Q.push_back( pair&lt;int, char&gt;(9, 'f') );
      Q.push_back( pair&lt;int, char&gt;(81, 'b') );
      Q.push_back( pair&lt;int, char&gt;(4, 'e') );
  
      make_heap(Q.begin(), Q.end(), myComp);
  
      pop_heap(Q.begin(), Q.end());
  
      cout &lt;&lt; Q.back().first &lt;&lt; ", " &lt;&lt; Q.back().second &lt;&lt; endl;
      Q.pop_back();
  
      return 0;
  }
  </code></pre>
  
  <p>and I am getting this following error</p>
  
  <pre><code>jdoodle.cpp: In function 'int main()':
  jdoodle.cpp:25:38: error: expected primary-expression before ')' token
    make_heap(Q.begin(), Q.end(), myComp);
                                        ^
  </code></pre>
  
  <p>I don't really understand what this means, what am I doing wrong?</p>