Listing 5 An implementation of float_array that extends the size of the array when it detects subscript out-of-bounds

// float_array::operator[] that extends the array on
// subscript out of bounds
float &float_array::operator[](size_t i)
   {
   if (i >= len)
      {
      float *new_array = new float[i + 1];
      assert(new_array != 0);
      size_t j;
      for (j = 0; j < len; ++j)
         new_array [j] = array[j];
      for (; j < i + 1; ++j)
         new_array[i] = 0;
      delete [] array;
      array = new_array;
      len = i + 1;
      }
   return array[i];
   }
/* End of File */