title: C++ public method inherited from base class can not access private member variable in derived class
body: <p>I have the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  using namespace std;
  
  class Animal{
  private:
      int age;
  public:
      Animal() : age(1) {}
      void toString(){
          cout &lt;&lt; "Age: " &lt;&lt; age &lt;&lt; endl;
      }
  };
  class Cat : public Animal
  {
  public:
      Cat() : age(5) {}
      /*
      void toString(){
          cout &lt;&lt; "Age: " &lt;&lt; age &lt;&lt; endl;
      }*/
  private:
      int age;
  };
  
  int main(){
      Cat tom;
      tom.toString();
  
      system("pause");
      return 0;
  }
  </code></pre>
  
  <p>But when I run the program, the age of the <strong>tom</strong> variable is 1, not 5. Does the <strong>toString</strong> can not read the <strong>age</strong> variable? If we open the /* */ the toString method in the Cat class, the age will be 5 !</p>
  
  <p>(My english is not good very much. Thanks)</p>