Error using custom operator< with std::less
<p>I am trying to overload the <code>&lt;</code> operator, but running into a problem.</p>

<p>Here is my implementation:</p>

<pre><code>int Vector3D::operator &lt; (const Vector3D &amp;vector)
{
   if(x&lt;vector.x)
       return 1;
   else
       return 0;
}
</code></pre>

<p>I am calling it using this code:</p>

<pre><code>std::map&lt;Vector3D, std::vector&lt;const NeighborTuple *&gt; &gt; position; 
std::set&lt;Vector3D&gt; pos; 
for (NeighborSet::iterator it = N.begin(); it != N.end(); it++)
{
    NeighborTuple const  &amp;nb_tuple = *it;

    Vector exposition;
    pos.insert (exposition);
    position[exposition].push_back (&amp;nb_tuple);
}
</code></pre>

<p>But I get this error:</p>

<blockquote>
  <p>/usr/include/c++/4.1.2/bits/stl_function.h: In member function ‘bool std::less&lt;_Tp&gt;::operator()(const _Tp&amp;, const _Tp&amp;) const [with _Tp = ns3::Vector3D]’:<br>
  /usr/include/c++/4.1.2/bits/stl_map.h:347:   instantiated from ‘_Tp&amp; std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::operator[](const _Key&amp;) [with _Key = ns3::Vector3D, _Tp = std::vector&lt;const ns3::olsr::NeighborTuple*, std::allocator&lt;const ns3::olsr::NeighborTuple*&gt; &gt;, _Compare = std::less&lt;ns3::Vector3D&gt;, _Alloc = std::allocator&lt;std::pair&lt;const ns3::Vector3D, std::vector&lt;const ns3::olsr::NeighborTuple*, std::allocator&lt;const ns3::olsr::NeighborTuple*&gt; &gt; &gt; &gt;]’<br>
  ../src/routing/olsr/olsr-routing-protocol.cc:853:   instantiated from here<br>
  /usr/include/c++/4.1.2/bits/stl_function.h:227: error: passing ‘const ns3::Vector3D’ as ‘this’ argument of ‘int ns3::Vector3D::operator&lt;(const ns3::Vector3D&amp;)’ discards qualifiers</p>
</blockquote>
