reference:
http://www.engr.sjsu...tt/SortFind.htm just go down until it talks about sort
this is how i learned to use sort. using a function that is basically a < operator
bool lessOp (YourClass a, YourClass b)
{
if (a.attribute < b.attribute) return true
else return false;
}
then with your vector of objects, just call the sort function from the algorithm library
sort (vec.begin(), vec.end(), lessOp); /////// you're passing a pointer to your lessOp function; using this pointer sort will call your function to compare the objects
or doing what the website i used above, just create a operator< function for you classes like this:
bool operator<(const Cperson& left, const Cperson& right)
{
return left.lastname < right.lastname;
}
now whenever you have 2 objects of that class and you do this var1<var2 it will called that function above.
just use your class instead of Cperson