const member function
<p>I have following piece of code:<br/></p>

<pre><code>class Test{
private:
    int id;
public:
     Test(int v):id(v) {}
     int getId() { return id;};          // however,I change this method signature
                                            int getId() const { return id;};
                                            and all the errors gone
};

 struct compare{
   bool operator()(const Test&amp; t1, const Test&amp; t2){
    return t1.getId() &lt; t2.getId();      // got error here
   }  
 };

 int main(int argc, char *argv[]){
   set&lt;Test, compare&gt; s;
   Test str[] = {Test(1), Test(2), Test(3)};
   for (int i = 0; i &lt; 3; ++i){
     s.insert(str[i]);
   }
   for (set&lt;Test&gt;::iterator it = s.begin(); it != s.end(); ++it){
     cout &lt;&lt; it-&gt;getId() &lt;&lt; "\n";        // got error here
   }    
   return EXIT_SUCCESS;
 }
</code></pre>

<p>I got this error when I called the method getId() with that code:<br/></p>

<pre><code>passing `const Test' as `this' argument of `int Test::getId()' discards qualifiers
</code></pre>

<p>I don't know why I need <b>const</b> in the method getId() to fix that error ? Thanks</p>
