Chapter 14: Tempaltes
- 14.2 Function-template specializations of
function template printArray
- L.7~8 Function Template
- Calling functions in L.29, L.34, L.39 causes the compiler to
instantiate printArray function-template specializations with type
int, double, character, respectively.
- 14.4 Class Templates
- Stack class template
- L.6~7 The class definition is preceded by the header
template<typename T>
.
- L.40~41 Member-function definitions of a class template are
function templates.
- L.41 Scope resolution operator is used with the
class-template name Stack<T> to tie each member-function
definition to the class tempalte's scope.
- fig14_03.cpp
- L.9 Stack<double> doubleStack(5); // size 5
- L.30 Stack<int> intStack; // default size 10
- Creating Function Templates to Test Class Template Stack<T>
- Stack class template
- fig14_04.cpp
- In the previous example, the code to manipulate doubleStack
and intStack are almost identical, so this is a great
opportunity to use a function template.
- L.11 The function template takes four arguments:
- a reference to an object of type Stack<T>
- a value of type T that will be the first value pushed
onto the Stack<T>
- a value of type T to increment the value
- a string representing the name of the Stack<T>
object