I don't understand exactly what you mean.
str_len is a private member variable that determines the length ( or size ) needed when dynamically allocating memory for strPtr:
|
char *strPtr = new char[str_len];
| |
and being a private member variable, it will only be updated by member functions and not directly by the user (which is why they are private).
inputLength member function, on the other hand, is used to determine the length of the string passed to the constructors ( or any function that takes a
String string or
const char * ) in which to figure out how much length is needed to add to str_len when resizing, prepending, removing, etc.
1 2 3 4 5
|
bool String::prepend( const char * string )
{
unsigned int length = inputLength( string ); // how many characters are in string
setLength( str_len + length ); // str_len += length
}
| |
...rather than having to rewrite the same for loop for each function that needs to determine the input string's length...
1 2 3 4 5 6 7 8 9
|
bool String::prepend( const char * string )
{
unsigned int length;
for ( int index = 0; string[index] != NULL; index++ )
length = index + 2; // plus one for NULL and plus one due to ZERO indexing
setLength( str_len + length );
}
| |
Although, now that I think about it, inputLength should probably return an unsigned int value in which to pass to setLength ( as shown in the previous example )...
|
unsigned int inputLength( unsigned int );
| |
And wouldn't that make setLength and inputLength "internal functions"?