title: operator< overloading for std::set
body: <p>This is my code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;set&gt;
  #include &lt;string&gt;
  
  class widget
  {
  public:
      widget(unsigned id) :
          m_id(id)
      {
      };
  
      ~widget(){};
  
      unsigned id(){ return m_id; };
      bool active(){ return m_active; };
      void set_active(bool active){ m_active = active; };
  
      friend bool operator&lt;(const widget&amp; lhs, const widget&amp; rhs);
  
      bool operator&lt;(const widget&amp; rhs)
      {
          return m_id &lt; rhs.m_id;
      }
  
  private:
      unsigned m_id;
      bool m_active{false};
  };
  
  bool operator&lt;(const widget&amp; lhs, const widget&amp; rhs)
  {
      return lhs.m_id &lt; rhs.m_id;
  }
  
  int main()
  {  
      std::set&lt;widget&gt; widgets;
  
      widget foo(5);
      widget bar(2);
  
      widgets.insert(foo);
      widgets.insert(bar);
  
      for(const auto&amp; hi : widgets)
          std::cout &lt;&lt; hi.id() &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>On compiling I get the error:
  <code>passing 'const widget' as 'this' argument of 'unsigned int widget::id()' discards qualifiers [-fpermissive]</code></p>
  
  <p>And I don't understand whats happening. Am I doing the operator overloading wrong? Also, do I need the operator&lt; as a member function with one parameter and as a free function with two parameters?</p>