title: initialize a base class pointer with an array of derived class objects
body: <p>Am I allowed to do the following?
  To initialize a base class pointer with an array of derived class objects? 
  The gnu g++ it is crashing when reaching the delete statement ...</p>
  
  <p>Any suggestion? Do I have to overload the new [] and delete operators? </p>
  
  <p>Thanks!</p>
  
  <pre><code>   #include &lt;iostream&gt;
  
     using std::endl;
     using std::cout;
     using std::cin;
  
     // base class --&gt; Base
  
     class Base {
     public:
  
     // constructor
  
     Base() {
         cout &lt;&lt; " --&gt; constructor --&gt; Base" &lt;&lt; endl;
     }
  
     // destructor
  
     virtual ~Base() {
         cout &lt;&lt; " --&gt; destructor --&gt; ~Base" &lt;&lt; endl;
     }
   };
  
   // derived class --&gt; D1
  
   class D1 : virtual public Base {
   public:
  
   // constructor
  
   D1() : Base(), x1(10) {
        cout &lt;&lt; " --&gt; constructor --&gt; D1" &lt;&lt; endl;
   }
  
   // destructor
  
   virtual ~D1() {
        cout &lt;&lt; " --&gt; destructor --&gt; ~D1" &lt;&lt; endl;
   }
  
   private:
  
   int x1;   
   };
  
   // the main program
  
   int main()
   {
      const int DIM = 100;
      Base * pb2 = new D1 [DIM];
      delete [] pb2;
  
      return 0;
   }
  </code></pre>