1. const objects are local to a file by default
2. Any variable used to store the result from the string size operation ought to be of type string::size_type. It is particularly important not to assign the return from size to an int.
Although we don't know the precise type of string::size_type, we do know that it is an unsigned type (Section 2.1.1, p. 34).
The same reasons to use string::size_type
as the type for a variable that holds the return from size apply when
defining a variable to serve as an index. A variable used to index a
string should have type string::size_type.
3. It is legal to delete a pointer whose value is zero; doing so has no effect:
int *ip = 0;
delete ip; // ok: always ok to delete a pointer that is equal to 0
The language guarantees that deleting a pointer that is equal to zero is safe.
4. If we reuse a file stream to read or
write more than one file, we must clear the stream before using it to
read from another file.
5. Ordinarily, single-parameter
constructors should be explicit unless there is an obvious reason to
want to define an implicit conversion. Making constructors explicit may avoid mistakes, and a user can explicitly construct an object when a conversion is useful. |