Re: [Boost-users] Question on ptr_vector class

boost-users-bounces@lists.boost.org wrote:
I would like to define two different sorting predicates for a class but I do not understand how to do this.
//meteorlogicalObj.hpp class meteorlogicalObj { public: meteorlogicalObj(int val, Point pt) : val_(val), pt_(pt){} virtual ~meteorlogicalObj() {}
// how would I go about creating these sorting functions that would work with the ptr_vector class bool sortOnValue(const meteorlogicalObj&, const meteorlogicalObj&); bool sortOnPoint(const meteorlogicalObj&, const meteorlogicalObj&); // ... private: int val_; Point pt_; };
//meteorlogicalObj.cpp #include "meteorlogicalObj.h"
bool meteorlogicalObj::sortOnValue(const meteorlogicalObj& metObj, const meteorlogicalObj& other) { return (metObj.val_ < other.val_); }
bool meteorlogicalObj::sortOnPoint(const meteorlogicalObj& metObj, const meteorlogicalObj& other) { return (metObj.pt_ < other.pt_); }
//main.cpp boost::ptr_vector<meteorlogicalObj> metObjVec;
//... fill vector
metObjVec.sort( sortOnValue() ); // this does not work, what is missing??? metObjVec.sort( sortOnPoint() ); // this does not work, what is missing???
I can see that I probably need the indect_fun but I do not know how to wrap my sorting function to pass them to the sorting function
Thank you for your assistance!
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
hi sebastien, try the following changes... 1) make the sort function static class meteorlogicalObj { ... static bool sortOnValue(const meteorlogicalObj&, const meteorlogicalObj&); ... }; 2) call sort like this metObjVec.sort(&meteorlogicalObj::sortOnValue); HTH dave
participants (1)
-
David Klein