Class Template Stack<T>’s Member Functions

The member-function definitions of a class template are function templates, but are not preceded with the template keyword and template parameters in angle brackets (< and >) when they’re defined within the class template’s body. As you can see, however, they do use the class template’s template parameter T to represent the element type. Our Stack class template does not define it’s own constructors—the default constructor provided by the compiler will invoke the deque’s default constructor. We also provide the following member functions in Fig. 18.1:

top (lines 12–15) returns a reference to the Stack’s top element.

push (lines 18–21) places a new element on the top of the Stack.

pop (lines 24–27) removes the Stack’s top element.

isEmpty (lines 30–33) returns a bool value—true if the Stack is empty and false otherwise.

size (lines 36–39) returns the number if elements in the Stack.

Each of these member functions delegates its responsibility to the appropriate member function of class template deque.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.13.51