Creating Class Template Stack<T>

The Stack class-template definition in Fig. 18.1 looks like a conventional class definition, with a few key differences. First, it’s preceded by line 7

template< typename T >

 1   // Fig. 18.1: Stack.h 2   // Stack class template. 3   #ifndef STACK_H 4   #define STACK_H 5   #include <deque> 6  7   template< typename T > 8   class Stack 9   {10   public:11      // return the top element of the Stack12      T& top()13      {14         return stack.front();15      } // end function template top16 17      // push an element onto the Stack18      void push( const T &pushValue )19      {20         stack.push_front( pushValue );21      } // end function template push22 23      // pop ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.