2

Another small question about STL:

i have Dictionary:

map <string,vector <Wordy> > Dictionary;

using structure Wordy:

struct Wordy{ int count; string word;}

also this structure have overloaded operator<

bool operator< (Wordy& One, Wordy& Two){return One.count<Two.count;}

but this sort() function from algorithm doesn't work!

sort(Dictionary.find(s)->second.begin(),Dictionary.find(s)->second.end());
gaussblurinc
  • 3,642
  • 9
  • 35
  • 64

2 Answers2

8

Your operator< should take its parameters by reference-to-const, I think that might be it:

bool operator< (const Wordy& One, const Wordy& Two){return One.count<Two.count;}
//              ^^^^^             ^^^^^
Xeo
  • 129,499
  • 52
  • 291
  • 397
0

check the post How to use std::sort with a vector of structures and compare function? . it explains how to use sort with a customized predicate function

Community
  • 1
  • 1
NirMH
  • 4,769
  • 3
  • 44
  • 69