title: Can a friend class object access base class private members on a derived class object in its member function?
body: <p>How object of Derived class <code>D d</code> can be accessed in friend class of <code>Base B</code>?</p>
  
  <p>Since there is no relationship between <code>D</code> and <code>F</code> then how it is possible to 
  access private member <code>b_var</code> of object of <code>D</code> in friend class?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  class B {              //Base class
      int b_var;
      friend class F;
  };
  
  class D : public B {    //Derived Class
      int d_var;
  };
  
  class F {              //This class is a friend class of B
  public:               //So it should access objects of B Not Derived Class 
      void func(D &amp;d) {      // object LIke in example d    
          d.b_var = 5;
          cout &lt;&lt; "I accessed D's Private Member b_var :" &lt;&lt; d.b_var;
      }
  };
  
  int main()
  {
      cout &lt;&lt; "fine";
  }
  </code></pre>