title: c++ STL sort using my define function error
body: <p>I know I can use my define function to sort an array, just like this:</p>
  
  <pre><code>bool cmp(int a, int b){
      return a &gt; b;
  }
  
  class SortTest{
  public :
      void testSort(){
          int a[] = { 1, 3, 4, 7, 0 };
          int n = 5;
          sort(a, a + n, cmp);                //work
          for (int i = 0; i &lt; n; i++){
              cout &lt;&lt; a[i] &lt;&lt; " ";
          }
      }
  };
  </code></pre>
  
  <p>But if I let function cmp in the SortTest class , it is not working.</p>
  
  <pre><code>class SortTest{
  public :
      bool cmp(int a, int b){
          return a &gt; b;
      }
      void testSort(){
          int a[] = { 1, 3, 4, 7, 0 };
          int n = 5;
          sort(a, a + n, &amp;SortTest::cmp);             // not work
          for (int i = 0; i &lt; n; i++){
              cout &lt;&lt; a[i] &lt;&lt; " ";
          }
      }
  };
  </code></pre>
  
  <p>I define two template SortClass and SortClass2 like <a href="http://www.cplusplus.com/reference/functional/greater/" rel="nofollow">greater template</a>  ， SortClass2 is use operator() and SortClass is cmp, only use operator() is working.</p>
  
  <pre><code>template &lt;class T&gt; struct SortClass {
      bool cmp (const T&amp; x, const T&amp; y) const { return x &gt; y; }
  };
  
  template &lt;class T&gt; struct SortClass2 {
      bool operator()(const T&amp; x, const T&amp; y) const { return x &gt; y; }
  };
  
  class SortTest{
  public :
      bool operator() (const int&amp; x, const int&amp; y) const { return x &gt; y; }
      void testSort(){
          int a[] = { 1, 3, 4, 7, 0 };
          int n = 5;
          //sort(a, a + n, &amp;SortClass&lt;int&gt;::cmp); //not work
          //sort(a, a + n, SortClass2&lt;int&gt;());    //work
          sort(a, a + n, SortTest());             //work
          for (int i = 0; i &lt; n; i++){
              cout &lt;&lt; a[i] &lt;&lt; " ";
          }
      }
  };
  </code></pre>
  
  <p>so,my question is why cmp function in the SortTest class is not working ,but use operator() is working? And if the cmp function is not in the class,it is working fine. Thanks a lot.</p>