title: Priority queue of struct's pointers
body: <p>I know that there are similar threads but after spending an hour trying to force my program to work, I decided to ask for a help.
  First of all. I've thought that I know c++ pretty well since I tried something which is very simple in PHP(programming language which I know best) but very complexed in c++ (at least very complexed for me). So I want to create priority_queue of struct's pointers. It's obvious that I need to create my own compare function. So I tried this code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;list&gt;
  #include &lt;queue&gt;
  
  using namespace std;
  
  typedef struct MI
  {
      int nr;
      int koszt;
      bool operator&lt;(const MI&amp; a, const MI&amp; b) {
        return a.koszt &gt; b.koszt;
  }
  } miasto, *miasto_wsk;
  
  int main()
  {
      priority_queue&lt;miasto_wsk&gt; q;
      miasto_wsk mi;
      mi = new miasto;
      mi-&gt;nr = 1;
      mi-&gt;koszt = 2;
      q.push(mi);
  }
  </code></pre>
  
  <p>And when I tried to compile my program I ended up with compilation error:</p>
  
  <pre><code>test.cpp:11:44: error: ‘bool MI::operator&lt;(const MI&amp;, const MI&amp;)’ must take exactly one argument
  </code></pre>
  
  <p>Can you explain me what I'm doing wrong and explain me how all this stuff with structs compare works(or give me a good tutorial/article which explains that from the beginning)</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I changed my code to this:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;list&gt;
  #include &lt;queue&gt;
  
  using namespace std;
  
  typedef struct miasto 
  {
      int nr;
      int koszt;
  } *miasto_wsk;
  
  bool myComparator(miasto_wsk arg1, miasto_wsk arg2) {
        return arg1-&gt;koszt &lt; arg2-&gt;koszt; //calls your operator
  }
  
  int main()
  {
      priority_queue&lt;miasto_wsk, vector&lt;miasto_wsk&gt;, myComparator&gt; q;
      miasto_wsk mi;
      mi = new miasto;
      mi-&gt;nr = 1;
      mi-&gt;koszt = 2;
      q.push(mi);
  }
  </code></pre>
  
  <p>And now I getting this error msg:</p>
  
  <pre><code>test.cpp: In function ‘int main()’:
  test.cpp:19:64: error: type/value mismatch at argument 3 in template parameter list for ‘template&lt;class _Tp, class _Sequence, class _Compare&gt; class std::priority_queue’
  test.cpp:19:64: error:   expected a type, got ‘myComparator’
  test.cpp:19:67: error: invalid type in declaration before ‘;’ token
  test.cpp:24:7: error: request for member ‘push’ in ‘q’, which is of non-class type ‘int’
  </code></pre>
  
  <p>What is the problem? Maybe I should use copies of structs instead pointers to structs?</p>
  
  <p><strong>EDIT2</strong></p>
  
  <p>This code doesn't produce any compilation errors:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;list&gt;
  #include &lt;queue&gt;
  
  using namespace std;
  
  typedef struct miasto 
  {
      int nr;
      int koszt;
      bool operator&lt; (const miasto&amp; rhs)
      {
      koszt &gt; rhs.koszt;
      }
  } *miasto_wsk;
  
  int main()
  {
      priority_queue&lt;miasto_wsk&gt; q;
      miasto_wsk mi;
      mi = new miasto;
      mi-&gt;nr = 1;
      mi-&gt;koszt = 22;
      q.push(mi);
  }
  </code></pre>
  
  <p>So @Angew idea seems to be wrong.</p>
  
  <p><strong>EDIT3:</strong>
  This is my final code. It not only compile without errors but also doing exactly what I want. Thank you so much @Angew</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;list&gt;
  #include &lt;queue&gt;
  
  using namespace std;
  
  typedef struct miasto 
  {
      int nr;
      int koszt;
  } *miasto_wsk;
  
  struct MyComparator {
      bool operator() (miasto_wsk arg1, miasto_wsk arg2) {
          return arg1-&gt;koszt &gt; arg2-&gt;koszt; //calls your operator
      }
  };
  
  
  int main()
  {
      //priority_queue&lt;miasto_wsk, vector&lt;miasto_wsk&gt;, myComparator&gt; q;
      priority_queue&lt;miasto_wsk, vector&lt;miasto_wsk&gt;, MyComparator&gt; q;
      miasto_wsk mi;
      mi = new miasto;
      mi-&gt;nr = 1;
      mi-&gt;koszt = 22;
      q.push(mi);
      miasto_wsk mi1;
      mi1 = new miasto;
      mi1-&gt;nr = 2;
      mi1-&gt;koszt = 50;
      q.push(mi1);
      miasto_wsk mi2;
      mi2 = new miasto;
      mi2-&gt;nr = 3;
      mi2-&gt;koszt = 1;
      q.push(mi2);
  
      cout &lt;&lt; q.top()-&gt;koszt &lt;&lt; endl;
      q.pop();
      cout &lt;&lt; q.top()-&gt;koszt &lt;&lt; endl;
      q.pop();
      cout &lt;&lt; q.top()-&gt;koszt &lt;&lt; endl;
      q.pop();
  }
  </code></pre>