Or rather not using binary predicates...
I'm probably missing something really simple here, but I can't see what I am doing wrong.
When using the STL vector template you can use the algorithm sort (defined in <algorithm>) to sort the vector. There are two versions available, one that takes a binary predicate as an argument and one that does not.
Now if you don't supply the binary predicate, the algorithm will attempt to sort using the < operator if it is defined which works fine if you have a vector of objects. BUT - if I have a vector of pointers to objects, it wont sort, in fact the operator< method is never called.
Now the above code works a treat for a vector declared as vector<CFoo> vec;Code:bool operator<(const CFoo &f) { if (data < f.data) return true; else return false; }
But if I have a vector declared as vector<CFoo *> vec; I can't seem to rewrite the operator. For a binary predicate it is simply a case of changing the predicate to a dereferencing predicate, but it doesn't appear to be case here as below...
Any really obvious mistakes pointed out are appreciated!Code:bool operator<(const CFoo *f) { if (data < f->data) return true; else return false; }