title: Some trouble with derived classes
body: <p>I am trying to implement the functions and classes below, but the output for arr[i].x is wrong. I correctly get arr[0].x = 0 and arr[1].x = 0, but arr[2].x does not return 0. Any ideas why?</p>
  
  <pre><code>class Base {
  public:
    int x;
  };
  
  class Derived : public Base {
  public:
  int y;
  void init(Base *b);
  void foo();
  };
  
  void Derived :: init(Base *b) {
    for( int i = 0; i &lt; 3; ++i) {
      b[i].x = 0;
    }
  }
  
  void Derived :: foo() { 
    Derived arr[3];
    init(arr);
    for( int i = 0; i &lt; 3; ++i) {
    cout&lt;&lt;"b["&lt;&lt;i&lt;&lt;"] "&lt;&lt;arr[i].x;
    }
  }
  
  
  int main()
  {
      Derived der;
      der.foo();
      return 0;
  }
  </code></pre>