# [C++] vectorT sorting

## Recommended Posts

Looking at the example from here I am trying to add sorting for a vector<T> in a class but I am getting "error: '__comp' cannot be used as a function" In my class I have
class QuadManager {
public:

};
Then in the class I try and sort
sort(m_quadArray.begin(), m_quadArray.end(), this);

##### Share on other sites
Antheus    2409
this is a pointer. Compare needs to be value type, since sort calls p() or p.operator(), not p->operator().

Solution would be to pass *this, but it is a very bad idea, since it is highly likely that one or more copies of compare object will be made.

Compare predicate is typically implemented as a standalone class.

##### Share on other sites
Thanks I created a "QuadSorter" class this worked.