title: inheritance data member between base and derived class c++
body: <p>why the apple object seed data member output difference?</p>
  
  <ol>
  <li><p>it seems fruit pointer point to fruit data member only. I can't overwrite this member in apple. why?</p></li>
  <li><p>how does line B internal work? fruit pointer point to apple 's plant function and then how this function decide which seed to call?</p></li>
  <li><p>at line C, does apple object pointer get static cast to fruit pointer?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  class fruit
  {
      public:
      int seed;
      fruit()
      {
          cout &lt;&lt;"fruit" &lt;&lt;endl;
          seed = 12;
      }
  
      virtual void plant()
      {
          cout &lt;&lt; seed &lt;&lt;endl;
      }
  };
  
  class apple:public fruit
  {
      public:
      int seed;
  
      apple()
      {
          cout &lt;&lt; "apple" &lt;&lt; endl;
          seed = 15;
      }
      void plant()
      {
          cout &lt;&lt; seed &lt;&lt; endl;
      }
  };
  
  int main()
  {
  
      vector&lt;fruit*&gt; ft;
      ft.push_back(new apple());// line C
  
      cout &lt;&lt; ft[0]-&gt;seed &lt;&lt; endl; // line A
      ft[0]-&gt;plant();// line B
  
      apple* ap = new apple();
      cout &lt;&lt; ap-&gt;seed &lt;&lt;endl; 
  
  }
  </code></pre></li>
  </ol>
  
  <p>output:</p>
  
  <pre><code>fruit
  apple
  12
  15
  fruit
  apple
  15
  </code></pre>