| Lynx876 (561) | ||||||||
|
Hello again cplusplus.com! As the title suggests, I'm trying to sort a vector by the std::string name within a struct. But I've run in to a problem that I don't know how to fix. The program compiles and runs fine, until it hits the following line: std::sort( table.begin(), table.end(), compareByWord );Which gives me the error:
This is my struct:
This is the function compareByWord:
I've run debug on the program, the function seems to run fine the whole way through. Pressing F10( Step Over, VS2012 ), takes me to xutility and shows me this template, which is when the error pops up, on line 9:
If possible. Could someone please tell me what's going wrong? Been searching the internet for a while now. Thanks for any help! (: | ||||||||
|
Last edited on
|
||||||||
| Lynx876 (561) | |
|
wow, and just like that! It works! I changed lines 21 and 22 in compareByWord, to: return ( lhs.name[ i ] < rhs.name[ i ] );
| |
|
Last edited on
|
|
| newbieg (173) | |
Shouldn't your compareByWord function return a full statement like : (lhs.name[ i ] < rhs.name[ i ]) or (lhs.name[ i ] > rhs.name[ i ])(The Sort() example from the resources seams to work like that, and when I tried to return true from their example I got the same error) http://www.cplusplus.com/reference/algorithm/sort/ | |
|
Last edited on
|
|
| Lynx876 (561) | |
|
It's a bool function. so; return 1 < 3;Would be true. (: Edit: It must have something to do with the sort, binary predicate. I'm not sure. I've never used sort with 3 parameters before today! lol. http://msdn.microsoft.com/en-us/library/ecdecxh1(v=vs.80).aspx | |
|
Last edited on
|
|