134 ◾ Software Essentials
is undened. Violation of the required precondition voids the contract
between the class designer and the application programmer. No guarantee
then remains for any resulting behavior.
Without an internal check, pop() may proceed with its attempt to
remove a value from the stack data structure. Such action may result in the
return of an invalid value. Consider a stack implemented as an array: the
“top” of the stack is an index into the array. When the stack is empty, this
index is invalid. In C++, use of an invalid index results in the extraction
of aninvalid data value (whatever value resident in memory so indexed).
Why? C++ does not automatically provide run-time checks on array
bounds. Hence, an application ...