Working with templates

Many C++ compilers allow you to work with templates.

A function template is a pattern for a set of functions. Similarly, a class template is a pattern for a set of classes. For example, a template for stack classes describes the form of data and functions in terms of an unspecified element type. To create a stack class, you supply a parameter, the actual type of data in the stack. Using this mechanism, you can create classes for stacks of strings or stacks of integers. These stack classes might contain different types of items, but they have the same default behaviors.

At compile or link time, the C++ compiler generates code for each template class. The code generation process is called template instantiation. In some cases, the process of template instantiation can conflict with clearmake building. These are possible symptoms of the conflict:

  • clearmake performs unnecessary rebuilds.
  • clearmake rebuilds an object that it could have winked in.
  • The C++ compiler does not recompile a template source that changed, resulting in a link error or a run-time error.
  • When clearmake winks in incremental repository files, information is lost.
  • The output of cleartool commands that display configuration records (for example, catcr or diffcr) is confusing.

The exact nature of the symptoms depends on the compiler you use. For many compilers, these problems do not arise. For other compilers, you can correct these problems by modifying your makefile or the program source.