C++ (Qt)bool Comp( int * i1, int * i2 ){ return *i1 > *i2;} /*bool Comp( float * f1, float * f2 ){ return *f1 > *f2;}*/ template <class T> struct MyClass { void SortData( void ) { std::sort(mData.begin(), mData.end(), Comp); } std::vector <T> mData;}; int main(int argc, char *argv[]){ MyClass <int *> test; test.SortData(); // MyClass <float *> test2;// test2.SortData(); return 0;}
C++ (Qt)...struct LessThen { bool operator ()(const Value* x, const Value* y) const { return *x < *y; }}; sort(valuesVector.begin(), valuesVector.end(), LessThen());...
C++ (Qt)inline bool Comp( const int * i1, const int * i2 ){ return *i1 < *i2;} inline bool Comp( const float * f1, const float * f2 ){ return *f1 < *f2;} template <class T> struct CompT { bool operator() ( const T t1, const T t2 ) { return Comp(t1, t2); }}; template <class T> struct MyClass { void SortData( void ) { std::sort(mData.begin(), mData.end(), CompT<T>()); } std::vector <T> mData;}; int main(int argc, char *argv[]){ MyClass <int *> test; test.SortData(); MyClass <float *> test2; test2.SortData(); return 0;}
C++ (Qt)template <typename T>bool Comp( T *v1, T *v2 ){ return *v1 > *v2;} template <typename T> struct MyClass { void SortData( void ) { std::sort(mData.begin(), mData.end(), Comp<T> ); } std::vector <T*> mData;}; int main( int, char ** ){ MyClass <int> test; test.SortData(); MyClass <float> test2; test2.SortData(); return 0;}
C++ (Qt)template <typename T>bool Comp( T *v1, T *v2 ){ return *v1 > *v2;}
C++ (Qt)struct Type{ int val;}; bool operator> ( const Type &t1, const Type &t2 ){ return t1.val > t2.val;} ... MyClass <Type> test3;test3.SortData();