title: sorting a vector of class in descending with std::sort
body: <p>I have this class called HPC_user and try to sort a vector of HPC_user in descending order with one of its member variables activity. It seems std::sort should do the job with a third argument. So I followed this thread and defined a new struct greater. </p>
  
  <p><a href="https://stackoverflow.com/questions/9025084/sorting-a-vector-in-descending-order">Sorting a vector in descending order</a></p>
  
  <pre><code>struct cpuComp
  {
    bool operator()(HPC_user const &amp; a, HPC_user const &amp; b)
    {
    return a.get_activity() &gt; b.get_activity();
    }
  };
  
  int main()
  {
    // do something;
      std::vector&lt;HPC_user&gt; users = db2class(ins, days);
    std::sort(users[0], users[len], cpuComp());
  //.....
  }
  </code></pre>
  
  <p>When I compiled the code, I got some errors:</p>
  
  <pre><code>    In file included from db2class.cpp:3:
      In file included from /usr/include/c++/4.2.1/iostream:44:
      In file included from /usr/include/c++/4.2.1/ostream:44:
      In file included from /usr/include/c++/4.2.1/ios:44:
      In file included from /usr/include/c++/4.2.1/bits/char_traits.h:45:
      In file included from /usr/include/c++/4.2.1/bits/stl_algobase.h:74:
      /usr/include/c++/4.2.1/bits/stl_iterator_base_types.h:128:35: error: no type named 'iterator_category' in 'HPC_user'
            typedef typename _Iterator::iterator_category iterator_category;
                    ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
      /usr/include/c++/4.2.1/bits/stl_algo.h:2854:24: note: in instantiation of template class 'std::iterator_traits&lt;HPC_user&gt;'
            requested here
            typedef typename iterator_traits&lt;_RandomAccessIterator&gt;::value_type
                             ^
      db2class.cpp:119:3: note: in instantiation of function template specialization 'std::sort&lt;HPC_user, bool (*)(const HPC_user &amp;,
            const HPC_user &amp;)&gt;' requested here
        std::sort(users[0], users[len], cpuComp);
        ^
  In file included from db2class.cpp:3:
  In file included from /usr/include/c++/4.2.1/iostream:44:
  In file included from /usr/include/c++/4.2.1/ostream:44:
  In file included from /usr/include/c++/4.2.1/ios:47:
  In file included from /usr/include/c++/4.2.1/bits/ios_base.h:46:
  In file included from /usr/include/c++/4.2.1/bits/locale_classes.h:46:
  In file included from /usr/include/c++/4.2.1/string:56:
  In file included from /usr/include/c++/4.2.1/algorithm:67:
  /usr/include/c++/4.2.1/bits/stl_algo.h:2864:19: error: invalid operands to binary expression ('HPC_user' and 'HPC_user')
        if (__first != __last)
            ~~~~~~~ ^  ~~~~~~
  db2class.cpp:122:3: note: in instantiation of function template specialization 'std::sort&lt;HPC_user, cpuComp&gt;' requested here
    std::sort(users[0], users[len], cpuComp());
    ^
  /usr/include/c++/4.2.1/bits/postypes.h:206:5: note: candidate template ignored: failed template argument deduction
      operator!=(const fpos&lt;_StateT&gt;&amp; __lhs, const fpos&lt;_StateT&gt;&amp; __rhs)
      ^
  /usr/include/c++/4.2.1/bits/stl_pair.h:109:5: note: candidate template ignored: failed template argument deduction
      operator!=(const pair&lt;_T1, _T2&gt;&amp; __x, const pair&lt;_T1, _T2&gt;&amp; __y)
      ^
  /usr/include/c++/4.2.1/bits/stl_iterator.h:294:5: note: candidate template ignored: failed template argument deduction
      operator!=(const reverse_iterator&lt;_Iterator&gt;&amp; __x,
      ^
  /usr/include/c++/4.2.1/bits/stl_iterator.h:344:5: note: candidate template ignored: failed template argument deduction
      operator!=(const reverse_iterator&lt;_IteratorL&gt;&amp; __x,
      ^
  /usr/include/c++/4.2.1/bits/allocator.h:120:5: note: candidate template ignored: failed template argument deduction
      operator!=(const allocator&lt;_T1&gt;&amp;, const allocator&lt;_T2&gt;&amp;)
      ^
  /usr/include/c++/4.2.1/bits/basic_string.h:2188:5: note: candidate template ignored: failed template argument deduction
      operator!=(const basic_string&lt;_CharT, _Traits, _Alloc&gt;&amp; __lhs,
  </code></pre>
  
  <p>What did I do wrong? What is the correct way to sort a vector of classes?</p>