I am trying to follow a link where a someone is trying to simplify the C++ sort reference http://www.cplusplus.com/forum/beginner/4817/ however I can not get the bool operator function to compile the way he has it.
I have vector of event objects. I want to sort the vector based on the event begin time. If the begin times were numbers, this would be easier but they are strings so I had to write functions to convert to uint64_t, all of my code up to this sort attempt is working as it should. Here is the code I am trying to get to work:
The bool function:
bool EWriter:: operator () ( Event &a, Event &b){
return (stringToTime(stringReturnWrap(a.getBeginTime())) < stringToTime(stringReturnWrap(b.getBeginTime())));
}
This code compiles but I can not figure out how to give it a name, and therefore I cannot reference it in the sort. Also, I would rather overload the < operator but I keep getting an error it needs a third argument.
Here is my sort:
sort(events->begin(), events->end(), someFunctionName);??
Slightly unrelated is that I know I am supposed to use const in the args but I can not call the functions of the Event class if I have them implemented.
const-ness to yourEvent &aandEvent &b?Event::getBeginTime()should be declaredconst. If it's not your code, maybe you could get the author to fix it. If it IS your code, FIX IT! 8v)