title: Cannot access protected member
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/477829/cannot-call-base-class-protected-functions">cannot call base class protected functions?</a>  </p>
  </blockquote>
  
  
  
  <p>I don't understand the following, when <code>Derived</code> inherits from <code>Base</code>, it gets access to its protected members which can be accessed through Derived functions. But if, <code>Base</code> class tries to access its own members from <code>Derived</code> class (which itself allows access to <code>Base</code>), it doesn't get access, why?</p>
  
  <pre><code>class Base {
  protected:
      int x;
  };
  
  class Derived : Base {
  public:
      void foo(Base* b);
  };
  
  
  void Derived::foo(Base* b) {
      b-&gt;x = 2;       // cannot access protected member,
                      // though Derived inherits from Base, why?
  }
  </code></pre>