// Stack of integers implemented with private inheritance // There is no error checking and in particular the stack // is limited to a fixed size. A GrowableArray would be better. #include "Array.h" class IntStack : private Array { public: // Make the length available - it is the maximum stack depth using Array::length; IntStack() : Array(20), top(0) { } // Stack interface is push and pop - each use the inherited // overloaded array operator, but we show two different ways // to access it void push(int v) { operator[](top++) = v; } int pop() { return (*this)[--top]; } bool empty() const { return top == 0; } private: int top; };