title: Why C++ inheritance not allow base class's public member inherit to derived class's private member?
body: <p>I wondering something about inheritance.</p>
  
  <pre><code>class Base{
     public:
       virtual int f(){return 0;}
  };
  class Derived:public Base{
     private:
       virtual int f(){return 100000;}
  };
  int g(Base &amp; b){
       return b.f();
  }
  int main(void){
       Base b;
       cout &lt;&lt; "g(b) = " &lt;&lt; g(b) &lt;&lt; endl;
       Derived d;
       cout &lt;&lt; "g(d) = " &lt;&lt; g(d) &lt;&lt; endl;
  </code></pre>
  
  <p>}    </p>
  
  <p>I have 2 class one is Base class that have virtual function f and the other is Derived class that have inheritance from Base class. But Derived class has virtual function f that is private member function.
  The problem is that in Base class virtual function f is public member, but in derived class virtual function f is private member.
  And when I execute this program the result is </p>
  
  <pre><code>g(b) = 0
  g(d) = 100000
  </code></pre>
  
  <p>I think this implies that the value Base &amp; b(In function g) can control Derived private member. So this is not allow to use.
  So I wondering why we shold not redefine public member in Base class to private member in Derived class?</p>