On 8/4/2010 8:12 PM, archie14 wrote:
I can't figure out how to use "sort" method in ptr_vector with the function object. Operator< should be defined, but for various reasons I cant define it in the class A, and I have to do the comparison between the A values using some other values.
Example:
class A { public: int i; };
class Compare { public: Compare (int i) : _i(i){} //this does not compile, but what's the proper way to define // function object for the sort method in ptr_vector? bool operator<(const A& v1, const A& v2) { return (v1.i> v2.i)&&(_i != 1); } private: int _i; };
ptr_vector<A> lst; Compare cmp(3); lst.sort(cmp);
The following works for me:
#include <iostream>
#include <functional>
#include