Hello. I've made a vector class (an realizable array but moving the array when it gets bigger etc..) and Im using templates to pass any object type like this :
template<typename ElemType>
class XVector {
}
struct myStruct {
int ID;
string name;
etc..
}
XVector<myStruct> myVector;
I made a search and a sort functions (in the XVector class) that takes the elements and compare them and in order for that to work I must overload the operators on myStruct so it can know what == or < means. So far so good but there are times when I need to sort the vector only on specific criteria for example only by ID and not by name; So instead of operator overloading I made function pointers in the class that are comparing.
int Compare(myStruct &elem1, myStruct &elem2 {
compare by elem1.id etc..
}
I make outside functions and pass them to the vector object function pointer.
Is that a normal thing to do or t here are better solutions? I'm not intersted in STL yet.
Thanks.