<b>(a)</b> class Stack { public: virtual void push(int x) = 0; virtual int pop() = 0; }; void foo(Stack& x) { // use push() and pop()... } <b>(b)</b> template <class Stack> void bar(Stack& x) { // use push and pop... }
Example 1: (a) Using an object-oriented approach to describe the stack requirements; (b) a function template.