title: C++ change member type in derived class
body: <p>I have a class Base1 that contains an array of objects of a different class Base2. I would like to have a derived class Derived1 that inherits everything from Base1 except the array is of type Derived2 (which is a derived class of Base2). For example, something like this:</p>
  
  <pre><code>class Base2{
          int a2;
  };
  
  class Derived2: public Base2{
          int b2;
  };
  
  class Base1{
          Base2* list;
  };
  
  class Derived1: public Base1{
          Derived2* list;
  };
  </code></pre>
  
  <p>My understanding is that in the above example, an object of Derived1 would actually have TWO arrays:</p>
  
  <pre><code>list
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Base1::list
  </code></pre>
  
  <p>which I don't want. </p>
  
  <p>The idea is that all the functionality of Base1 should still work for a Derived1 object since Derived2 "is a" Base2. It would be really dirty, but I guess I could just delete[] the Base1::list array in the Derived1 constructor. </p>
  
  <p>Does anyone see a solution to this? It seems like something that would happen frequently, and I cannot believe a simple solution does not exist. Would using templates work? My thought was no, since all the functionality in Base1 and Derived1 need to know that they are dealing with Base2 and Derived2 objects, respectively.</p>