"Michael" <sl***********@hotmail.com> writes:
[snip]
how do i now sort according to a or b?? do I pass in a function pointer
to sort(.....)??
You may use either a pointer to a function or a functor:
#include <vector>
#include <algorithm>
using std::vector;
using std::sort;
class C
{
public:
int a,b;
};
bool comp(C const& lhs, C const& rhs){return lhs.a < rhs.a;}
struct compare
{
bool operator()(C const& lhs, C const& rhs){return lhs.a < rhs.a;}
};
int main()
{
vector<C> vecC;
//Use pointer to function.
sort(vecC.begin(),vecC.end(),comp);
//Use functor.
sort(vecC.begin(),vecC.end(),compare());
}