I would like to sort a vector
vector object;
Where myclass contains many int variabl
Like explained in other answers you need to provide a comparison function. If
you would like to keep the definition of that function close to the sort
call (e.g. if it only makes sense for this sort) you can define it right there
with boost::lambda. Use boost::lambda::bind to call the member function.
To e.g. sort by member variable or function data1:
#include
#include
#include
#include
using boost::lambda::bind;
using boost::lambda::_1;
using boost::lambda::_2;
std::vector object(10000);
std::sort(object.begin(), object.end(),
bind(&myclass::data1, _1) < bind(&myclass::data1, _2));