title: How to insert values in a c++ set
body: <p>I'm trying to create a set of custom objects of the class Point</p>
  
  <p>point.h</p>
  
  <pre><code>#ifndef POINT_H
  #define POINT_H
  
  class Point
  {
        float x_coordinate,y_coordinate;
        public:
               Point(float x, float y):x_coordinate(x),y_coordinate(y)
               {}
  
               float get_x()
               {
                     return x_coordinate;
               }
  
               float get_y()
               {
                     return y_coordinate;
               }
  
               bool operator==(Point rhs)
               {
                    if( ((int)x_coordinate == (int)rhs.get_x()) &amp;&amp; ((int)y_coordinate == (int)rhs.get_y()) )
                        return true;
                    else return false;
               }
  
               bool operator&lt;(Point rhs)
               {
                    if((int)x_coordinate &lt; (int)rhs.get_x())
                        return true;
                    else return false;
               }
  };
  
  #endif
  </code></pre>
  
  <p>I've just started to write the driver</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;set&gt;
  #include "point.h"
  using namespace std;
  
  
  
  int main()
  {
      Point p1(-10,-10),p2(-10,10),p3(10,10),p4(10,-10);
      set&lt;Point&gt; points_set = set&lt;Point&gt;();
      points_set.insert(p1);
  
      return 0;
  }
  </code></pre>
  
  <p>but I get this error during compilation, I have overloaded the comparison and equality operator, what else must I do to get it to work?</p>
  
  <pre><code>In file included from /usr/include/c++/4.6/string:50:0,
                   from /usr/include/c++/4.6/bits/locale_classes.h:42,
                   from /usr/include/c++/4.6/bits/ios_base.h:43,
                   from /usr/include/c++/4.6/ios:43,
                   from /usr/include/c++/4.6/ostream:40,
                   from /usr/include/c++/4.6/iostream:40,
                   from driver.cpp:1:
  /usr/include/c++/4.6/bits/stl_function.h: In member function ‘bool std::less&lt;_Tp&gt;::operator()(const _Tp&amp;, const _Tp&amp;) const [with _Tp = Point]’:
  /usr/include/c++/4.6/bits/stl_tree.h:1267:4:   instantiated from ‘std::pair&lt;std::_Rb_tree_iterator&lt;_Val&gt;, bool&gt; std::_Rb_tree&lt;_Key, _Val, _KeyOfValue, _Compare, _Alloc&gt;::_M_insert_unique(const _Val&amp;) [with _Key = Point, _Val = Point, _KeyOfValue = std::_Identity&lt;Point&gt;, _Compare = std::less&lt;Point&gt;, _Alloc = std::allocator&lt;Point&gt;]’
  /usr/include/c++/4.6/bits/stl_set.h:410:29:   instantiated from ‘std::pair&lt;typename std::_Rb_tree&lt;_Key, _Key, std::_Identity&lt;_Key&gt;, _Compare, typename _Alloc::rebind&lt;_Key&gt;::other&gt;::const_iterator, bool&gt; std::set&lt;_Key, _Compare, _Alloc&gt;::insert(const value_type&amp;) [with _Key = Point, _Compare = std::less&lt;Point&gt;, _Alloc = std::allocator&lt;Point&gt;, typename std::_Rb_tree&lt;_Key, _Key, std::_Identity&lt;_Key&gt;, _Compare, typename _Alloc::rebind&lt;_Key&gt;::other&gt;::const_iterator = std::_Rb_tree_const_iterator&lt;Point&gt;, std::set&lt;_Key, _Compare, _Alloc&gt;::value_type = Point]’
  driver.cpp:12:25:   instantiated from here
  /usr/include/c++/4.6/bits/stl_function.h:236:22: error: passing ‘const Point’ as ‘this’ argument of ‘bool Point::operator&lt;(Point)’ discards qualifiers [-fpermissive]
  </code></pre>