_PROGRAMMER'S BOOKSHELF_ by Andrew Schulman Example 1: A stack template in C++ 3.0 // stack.h template class stack { T *v, *p; int sz; public: // all the following functions are inline stack(int s) { v = p = new T[sz = s]; } ~stack() { delete[] v; } void push(T a) { *p++ = a; } T pop() { return *--p; } int size() const { return p-v; } } Example 2: Creating two different classes of stack, from the same template #include #include "stack.h" main() { stack si(100); // stack of 100 ints stack sc(100); // stack of 100 chars for (int i=0; i<10; i++) { si.push(i); sc.push(i); } while (si.size()) // pop everything and cout << si.pop() << ' ' ; // display it cout << '\n' ; } Example 3 mov bx, word ptr [si.p] mov ax, word ptr [i] mov word ptr [bx], ax ; *p = i add word ptr [si.p], 2 ; p += sizeof(int)