/* Copyright (c) 1992 by AT&T Bell Laboratories. */ /* Advanced C++ Programming Styles and Idioms */ /* James O. Coplien */ /* All rights reserved. */ template class Stack; template class Cell { friend class Stack; private: Cell *next; T *rep; Cell(T *r, Cell *c): rep(r), next(c) { } }; template class Stack { public: T *pop(); T *top() { return rep->rep; } void push(T *v) { rep = new Cell(v, rep); } int empty() { return rep == 0; } Stack() { rep = 0; } private: Cell *rep; }; template T *Stack::pop() { T *ret = rep->rep; Cell *c = rep; rep = rep->next; delete c; return ret; }