|
|
Objections need not be addressed in the user program at all if the client programmer is satisfied with the default actions that take place on the stack underflow and overflow errors. For example, consider the following routine which reads integers from standard input and prints them in reverse order:
#include <Stack.h>
#include <iostream.h>
Stack st;
int pnum=0;
void silly_routine()
{
int i;
while( ( cin >> i ) {
st.push(i);
pnum++;
}
while(pnum > 0) {
cout << st.pop() << "\ n";
pnum--;
}
}
When the 11th integer is read in and push()
'ed
onto the stack, the
Stack::overflow
Objection will be raised and the
program will abort.