Generating template class instantiations

If you instantiate new template classes from existing class templates and define HIDE_TEMPLATE_DEFINITIONS when you build your project, you must create or modify a file in your project directory called ProjectNameInstantiations.C.

The instantiations file

The source directory for every shared library or server that you develop must contain an instantiations file, which defines the template classes that your shared library or server instantiates. This example, MemHeapInstantiations.C, is taken from the memory heap project:

      // $Revision: 1.1 $
      #ifndef HIDE_TEMPLATE_DEFINITIONS
      #define HIDE_TEMPLATE_DEFINITIONS
      #endif
      
      #include "Collections.h"
      #include "Storage.h"
      
      #define MAKE_TCollectionOf_DEFINITIONS_VISIBLE
      #define MAKE_TComparator_DEFINITIONS_VISIBLE
      #define MAKE_TStreamer_DEFINITIONS_VISIBLE
      
      #pragma defineonly
      #include "CollectionsImplementation.h"
      
      #pragma define( TCollectionOf<TMemoryHeap> )
      #pragma define( TComparator<TMemoryHeap> )
      #pragma define( TStreamer<TMemoryHeap> )
      
      #undef MAKE_TCollectionOf_DEFINITIONS_VISIBLE
      #undef MAKE_TComparator_DEFINITIONS_VISIBLE
      #undef MAKE_TStreamer_DEFINITIONS_VISIBLE

Adding new instantiations

To add new instantiations to your shared library or server, create or modify the instantiations file for the project that contains your code:

  1. Add a line of this form for each class template you use:
      #define MAKE_ClassTemplateName_DEFINITIONS_VISIBLE
  2. Add any necessary #include statements.
  3. Add this line:
      #pragma defineonly
    This statement is very important; it tells the compiler to instantiate only the explicitly requested template classes.
  4. Add a line of this form for each template class you want to generate:
      #pragma define( ClassTemplateName )
  5. Add a line of this form for each class template you use:
      #undef MAKE_ClassTemplateName_DEFINITIONS_VISIBLE
NOTE If you create a new instantiations file, remember to add it to your .PinkMake file. ProjectNameInstantiations.C must be the first file listed in the source: section for your library or server.

Determining which class templates to add

To determine which class templates to add to the instantiations file, you must compile and link your project. The final linking pass issues error messages about undefined symbols, which you can use to identify missing class templates. For a template class such as TPileOf<int>, for example, you might get error messages of this form:

    "ld: error-code ERROR: Undefined symbol: TPileOf<int>::MemberFunction"
Add the missing class templates to the instantiations file and build your project again. You might need to repeat this process several times to identify all the missing class templates.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker