~ubuntu-branches/ubuntu/gutsy/c++-annotations/gutsy

« back to all changes in this revision

Viewing changes to yo/templatefunctions/baseclass.yo

  • Committer: Bazaar Package Importer
  • Author(s): Frank B. Brokken
  • Date: 2007-06-15 19:31:12 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070615193112-i48grmnykrf1ipqf
Tags: 7.0.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
5
 
        hi(concrete class)
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
 
5
can, like
 
6
        hi(ordinary class)
 
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.
11
11
 
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.
16
16
 
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):
21
21
        verb(
22
22
    template <typename Type, typename Object>
51
51
        )
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:
58
58
        verb(
59
59
    int main()
60
60
    {
61
 
        Vector<string> vs;      // note: not `std::vector'
 
61
        Vector<string> vs;      // `Vector' instead of `std::vector'
62
62
        Vector<int> vi;
63
63
 
64
64
        sortVector(vs, CaseLess());