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,566
  • 9
  • 33
  • 63

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
  • 126,658
  • 49
  • 285
  • 389
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,477
  • 2
  • 40
  • 64