title: C++ operator < overloading
body: <p>I have a problem with overloading of the &lt; operator.
  I have this class:</p>
  
  <p>WordEntry.h:</p>
  
  <pre><code>class WordEntry
  {
  public:
      WordEntry(string word);
      ~WordEntry();
  
      bool operator&lt;(const WordEntry otherWordEntry);
  
      string getWord();
  
  private:
      string _word;
  };
  </code></pre>
  
  <p>WordEntry.cpp(I removed constructor &amp; destructor):</p>
  
  <pre><code>string WordEntry::getWord()
  {
     return _word;
  }
  
  
  bool WordEntry::operator&lt;(WordEntry otherWordEntry)
  {
     return  lexicographical_compare(_word.begin(),_word.end(),otherWordEntry.getWord().begin(),otherWordEntry.getWord().end());
  }
  </code></pre>
  
  <p>Everything is fine when I'm using it in main.cpp like that:</p>
  
  <pre><code>    WordEntry w1("Der");
      WordEntry w2("das");
  
      if (w1.operator&lt;(w2)) {
         cout &lt;&lt; "w1 &gt; w2";
      }
      else 
      {
         cout &lt;&lt; "w2 &gt; w1";
      }
  </code></pre>
  
  <p>But when I call <code>sort()</code> on a <code>vector</code> with <code>WordEntry</code> objects, I'll get the error message </p>
  
  <blockquote>
    <p>Invalid operands to binary expression ('const WordEntry' and 'const
    WordEntry')</p>
  </blockquote>
  
  <p>and it points to <code>stl_algo.h</code>.</p>
  
  <p>Does anyone knows what's going on here?</p>