home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / c / cuj9301.zip / 1101095B < prev    next >
Text File  |  1992-11-03  |  519b  |  22 lines

  1. //
  2. // float_array::operator[] that extends the array on
  3. // subscript out of bounds
  4. //
  5. float &float_array::operator[](size_t i)
  6.     {
  7.     if (i >= len)
  8.         {
  9.         float *new_array = new float[i + 1];
  10.         assert(new_array != 0);
  11.         size_t j;
  12.         for (j = 0; j < len; ++j)
  13.             new_array[j] = array[j];
  14.         for (; j < i + 1; ++j)
  15.             new_array[i] = 0;
  16.         delete [] array;
  17.         array = new_array;
  18.         len = i + 1;
  19.         }
  20.     return array[i];
  21.     }
  22.