Vax C90-EL SERIES Service Manual Page 129

  • Download
  • Add to my manuals
  • Print
  • Page
    / 216
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 128
Cray Standard C++ Template Instantiation [6]
A template describes a class or function that is a model for a family of related
classes or functions. The act of generating a class or function from a template is
called template instantiation.
Note: The information in this chapter does not pertain to C or the Cray
Standard C compiler.
For example, a template can be created for a stack class, and then a stack of
integers, a stack of floats, and a stack of some user-defined type can be used. In
source code, these might be written as
Stack<int>, Stack<float>, and
Stack<X>. From a single source description of the template for a stack, the
compiler can create instantiations of the template for each of the types required.
The instantiation of a class template is always done as soon as it is needed during
a compilation. However, the instantiations of template functions, member
functions of template classes, and static data members of template classes
(template entities) are not necessarily done immediately for the following
reasons:
The preferred end result is one copy of each instantiated entity across all
object files in a program. This applies to entities with external linkage.
A specialization of a template entity is allowed. For example, a specific
version of Stack<int>, or of just Stack<int>::push could be written
to replace the template-generated version and to provide a more efficient
representation for a particular data type.
Because the compiler does not know about specializations of entities provided
in future compilations when compiling a reference to a template entity, it
cannot automatically instantiate the template in source files that contain
references to the template.
If a template function is not referenced, it should not be compiled because
such functions could contain semantic errors that would prevent compilation.
Therefore, a reference to a template class should not automatically instantiate
all the member functions of that class.
Note: Certain template entities, such as inline functions, are always
instantiated when they are used.
If the compiler is responsible for doing all instantiations automatically, it can only
do so for the entire program. That is, the compiler cannot make decisions about
S217936 109
Page view 128
1 2 ... 124 125 126 127 128 129 130 131 132 133 134 ... 215 216

Comments to this Manuals

No comments