title: object in a set iterator
body: <p>I can get a method of a class in a set iterator ?   </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;set&gt;
  class student{
    public:
       student(std::string n){
          name=n;
       }
       void print(){
          std::cout &lt;&lt; name &lt;&lt; std::endl;
       }
       bool operator &lt; (const student &amp; s1){ return true;}
       bool operator = (const student &amp; s1){ return true;}
    private:
       std::string name;
  };
  int main(){
    std::set&lt;student&gt; studs;
    studs.insert(student("name01"));
    studs.insert(student("name02"));
    std::set&lt;student&gt;::iterator it;
    for(it = studs.begin(); it != studs.end(); it++)
        (*it).print() ;
  }
  </code></pre>
  
  <p>I get this error</p>
  
  <pre><code>students.cpp: In function ‘int main()’:  
  students.cpp:22: error: passing ‘const student’ as ‘this’ argument of ‘void student::print()’ discards qualifiers
  /usr/include/c++/4.2.1/bits/stl_function.h: In member function ‘bool std::less&lt;_Tp&gt;::operator()(const _Tp&amp;, const _Tp&amp;) const [with _Tp = student]’:
  /usr/include/c++/4.2.1/bits/stl_tree.h:982:   instantiated from ‘std::pair&lt;typename std::_Rb_tree&lt;_Key, _Val, _KeyOfValue, _Compare, _Alloc&gt;::iterator, bool&gt; std::_Rb_tree&lt;_Key, _Val, _KeyOfValue, _Compare, _Alloc&gt;::_M_insert_unique(const _Val&amp;) [with _Key = student, _Val = student, _KeyOfValue = std::_Identity&lt;student&gt;, _Compare = std::less&lt;student&gt;, _Alloc = std::allocator&lt;student&gt;]’
  /usr/include/c++/4.2.1/bits/stl_set.h:307:   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 _Key&amp;) [with _Key = student, _Compare = std::less&lt;student&gt;, _Alloc = std::allocator&lt;student&gt;]’
  students.cpp:18:   instantiated from here
  /usr/include/c++/4.2.1/bits/stl_function.h:227: error: passing ‘const student’ as ‘this’ argument of ‘bool student::operator&lt;(const student&amp;)’ discards qualifiers
  </code></pre>
  
  <p>with  </p>
  
  <pre><code>     bool operator&lt;(const student &amp; s1) const { return true;}  
       bool operator==(const student &amp; s1) const { return true;}  
  </code></pre>
  
  <p>now work!! O_o',  </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;set&gt;
  class student{
    public:
       student(std::string n){
          name=n;
       }
       void print() const {
          std::cout &lt;&lt; name &lt;&lt; std::endl;
       }
       bool operator&lt;(const student &amp; s1) const { return true;}
       bool operator==(const student &amp; s1) const { return true;}
    private:
       std::string name;
  };
  int main(){
    std::set&lt;student&gt; studs;
    studs.insert(student("name01"));
    studs.insert(student("name02"));
    std::set&lt;student&gt;::iterator it;
    for(it = studs.begin(); it != studs.end(); it++)
        it-&gt;print() ;
  }
  </code></pre>