Previous Slide Last Time Next Slide

Previously, we wrote a String class that addressed instances of two of those categories:

Problem Solution using a String class
The error of accessing characters outside a string Make the String's data private and only allow access to the characters of the string via a method that does range-checking.
The inefficient acquisition of a string's length Store the length of the string as an additional piece of data in the String class. Update that field every time the contents of the string is altered.


BU CAS CS - A String Class: Part II - Lab
Copyright © 1993-2000 by Robert I. Pitts <rip@bu.edu> All Rights Reserved.