Testing Class Template Stack<T>

Now, let’s consider the driver (Fig. 18.2) that exercises the Stack class template. The driver begins by instantiating object doubleStack (line 9). This object is declared as a Stack<double> (pronounced “Stack of double”). The compiler associates type double with type parameter T in the class template to produce the source code for a Stack class with elements of type double that actually stores its elements in a deque<double>.

 1   // Fig. 18.2: fig18_02.cpp 2   // Stack class template test program. 3   #include <iostream> 4   #include "Stack.h" // Stack class template definition 5   using namespace std; 6  7   int main() 8   { 9      Stack< double > doubleStack; // create a Stack ...

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.