Wyo C++ Ch. 13 Notes
Objective #1: Understand various functions that can be used with built-in C++ character arrays.
if (strcmp(string1, string2) = = 0)
{
cout << "The strings are the same!\n";
}
causes the message to be printed on the screen if the two character arrays, string1 and string2, are equivalent. The strcmp function returns a negative value if the first character array is alphabetically less than the second and it returns a positive value if the second character array is alphabetically less than the first one. It returns a zero if and only if the two character arrays are exactly the same.
Objective #2: Be able to use the apstring class.
Objective #3: Understand advanced object-oriented concepts used in the apstring class.
It is used to keep the returned object from being modified within the
call statement of the client program. In the overloaded assignment operator
of the apstring class, const is used in this way,
const apstring & operator = ( char ch );
Consider a client program with the following code:
apstring myInitial;
(myInitial = 'P') = 'G';
The assignment statement above is ambiguous and therefore disallowed
by the use of const. The value returned as myInitial after the execution
of the parentheses is 'P' but the use of const keeps it from being modified
further when the second assignment operator is applied in the very
same statement. This use of const would however allow two separate
statements to assign different values to myInitial as in:
myInitial = 'P';
myInitial = 'G';
It is common and wise to use const in this way when overloading assignment
and compound operators.