1
Although the em(construction) of template classes will only be constructed in
2
chapter ref(TEMPCLASS), template classes have already extensively been
1
Although the em(construction) of class templates is the topic of
2
chapter ref(TEMPCLASS), class templates have already extensively been
3
3
em(used) earlier. For example, abstract containers (covered in chapter
4
ref(Containers)) are actually defined as template classes. Like
6
concrete classes (i.e., non-template classes), template classes can
7
participate in the construction of
4
ref(Containers)) are actually defined as class templates. Class templates
7
ordinary classes, participate in the construction of
8
8
i(class hierarchies).
9
In section ref(DERIVEDTEMPCLASS) it is shown how a i(template class) can
10
be derived from another template class.
9
In section ref(DERIVEDTEMPCLASS) it is shown how a i(class template) can
10
be derived from another class template.
12
As template class derivation remains to be covered, the following
12
As class template derivation remains to be covered, the following
13
13
discussion is necessarily somewhat abstract. Optionally, the reader may of
14
course skip briefly to section ref(DERIVEDTEMPCLASS), to read this
14
course skip briefly to section ref(DERIVEDTEMPCLASS), and return back to this
15
15
section thereafter.
17
In this section it should now be assumed, for the sake of argument, that a
18
template class tt(Vector) has somehow been derived from a tt(std::vector).
19
Furthermore, assume that the following template function has been
17
In this section it should be assumed, for the sake of argument, that a
18
class template tt(Vector) has somehow been derived from a tt(std::vector).
19
Furthermore, assume that the following function template has been
20
20
constructed to sort a vector using some function object tt(obj):
22
22
template <typename Type, typename Object>
52
52
Applying the transformation
53
53
hi(transformation to a base class)
54
hi(template class: transformation to a base class)
54
hi(class template: transformation to a base class)
55
55
em(transformation to a base class instantiated from a class template), the
56
template function tt(sortVectors()) may now also be used to sort tt(Vector)
56
function template tt(sortVectors()) may now also be used to sort tt(Vector)
57
57
objects. For example:
61
Vector<string> vs; // note: not `std::vector'
61
Vector<string> vs; // `Vector' instead of `std::vector'
64
64
sortVector(vs, CaseLess());