title: Why == overloading can access private members of argument
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/12447782/why-private-value-of-the-obj-can-be-changed-by-class-instance">why private value of the obj can be changed by class instance?</a>  </p>
  </blockquote>
  
  
  
  <p>Consider the following (partial) code:</p>
  
  <pre><code>class Group {
      private:
        int id;
  
      public:
        void set_id(int);
        int get_id();
        bool operator==(const Group&amp;);
  };
  
  
  bool Group::operator==(const Group&amp; g) {
      if(g.id == this-&gt;id) {  /* id is private? */
              return true;
      }
  
      return false;
  }
  </code></pre>
  
  <p>The code compiles and results seem proper. However, in the <code>if</code> part of the operator overloading implementation, we are directly accessing the private member of its argument - <code>const Group&amp; g</code>, but isn't such an access invalid?</p>