title: simple C++ hash_set example
body: <p>I am new to C++ and STL. I am stuck with the following simple example of a hash set storing custom data structures:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;ext/hash_set&gt;
  
  using namespace std;
  using namespace __gnu_cxx;
  
  struct trip {
      int trip_id;
      int delta_n;
      int delta_secs;
  
      trip(int trip_id, int delta_n, int delta_secs){
          this-&gt;trip_id = trip_id;
          this-&gt;delta_n = delta_n;
          this-&gt;delta_secs = delta_secs;
      }
  };
  
  
  struct hash_trip
  {
      size_t operator()(const trip t)
      {
          hash&lt;int&gt; H;
          return H(t.trip_id);
      }
  };
  
  struct eq_trip
  {
      bool operator()(const trip t1, const trip t2) {
          return (t1.trip_id==t2.trip_id) &amp;&amp;
          (t1.delta_n==t2.delta_n) &amp;&amp;
          (t1.delta_secs==t2.delta_secs);
      }
  };
  
  int main()
  {
      hash_set&lt;trip, hash_trip, eq_trip&gt; trips;
  
      trip t  = trip(3,2,-1);
      trip t1  = trip(3,2,0);
  
      trips.insert(t);
  
  }
  </code></pre>
  
  <p>when I try to compile it, I get the following error message:</p>
  
  <pre><code>/usr/include/c++/4.2.1/ext/hashtable.h: In member function ‘size_t __gnu_cxx::hashtable&lt;_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc&gt;::_M_bkt_num_key(const _Key&amp;, size_t) const [with _Val = trip, _Key = trip, _HashFcn = hash_trip, _ExtractKey = std::_Identity&lt;trip&gt;, _EqualKey = eq_trip, _Alloc = std::allocator&lt;trip&gt;]’:
  /usr/include/c++/4.2.1/ext/hashtable.h:599:   instantiated from ‘size_t __gnu_cxx::hashtable&lt;_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc&gt;::_M_bkt_num(const _Val&amp;, size_t) const [with _Val = trip, _Key = trip, _HashFcn = hash_trip, _ExtractKey = std::_Identity&lt;trip&gt;, _EqualKey = eq_trip, _Alloc = std::allocator&lt;trip&gt;]’
  /usr/include/c++/4.2.1/ext/hashtable.h:1006:   instantiated from ‘void __gnu_cxx::hashtable&lt;_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc&gt;::resize(size_t) [with _Val = trip, _Key = trip, _HashFcn = hash_trip, _ExtractKey = std::_Identity&lt;trip&gt;, _EqualKey = eq_trip, _Alloc = std::allocator&lt;trip&gt;]’
  /usr/include/c++/4.2.1/ext/hashtable.h:437:   instantiated from ‘std::pair&lt;__gnu_cxx::_Hashtable_iterator&lt;_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc&gt;, bool&gt; __gnu_cxx::hashtable&lt;_Val, _Key, _HashFcn, _ExtractKey, _EqualKey, _Alloc&gt;::insert_unique(const _Val&amp;) [with _Val = trip, _Key = trip, _HashFcn = hash_trip, _ExtractKey = std::_Identity&lt;trip&gt;, _EqualKey = eq_trip, _Alloc = std::allocator&lt;trip&gt;]’
  /usr/include/c++/4.2.1/ext/hash_set:197:   instantiated from ‘std::pair&lt;typename __gnu_cxx::hashtable&lt;_Value, _Value, _HashFcn, std::_Identity&lt;_Value&gt;, _EqualKey, _Alloc&gt;::const_iterator, bool&gt; __gnu_cxx::hash_set&lt;_Value, _HashFcn, _EqualKey, _Alloc&gt;::insert(const typename __gnu_cxx::hashtable&lt;_Value, _Value, _HashFcn, std::_Identity&lt;_Value&gt;, _EqualKey, _Alloc&gt;::value_type&amp;) [with _Value = trip, _HashFcn = hash_trip, _EqualKey = eq_trip, _Alloc = std::allocator&lt;trip&gt;]’
  try.cpp:45:   instantiated from here
  /usr/include/c++/4.2.1/ext/hashtable.h:595: error: passing ‘const hash_trip’ as ‘this’ argument of ‘size_t hash_trip::operator()(trip)’ discards qualifiers
  </code></pre>
  
  <p>What am I doing wrong?</p>