To use -qtempinc, you must structure your application
as follows:
- Declare your class templates and function templates in template
header files, with a .h extension.
- For each template declaration file, create a template implementation
file. This file must have the same file name as the template declaration
file and an extension of .c or .t,
or the name must be specified in a #pragma implementation directive.
For a class template, the implementation file defines the member functions
and static data members. For a function template, the implementation
file defines the function.
- In your source program, specify an #include directive
for each template declaration file.
- Optionally, to ensure that your code is applicable for both -qtempinc and -qnotempinc compilations,
in each template declaration file, conditionally include the corresponding
template implementation file if the __TEMPINC__ macro is not defined.
(This macro is automatically defined when you use the -qtempinc compilation
option.) This produces the following results:
- Whenever you compile with -qnotempinc, the
template implementation file is included.
- Whenever you compile with -qtempinc, the compiler
does not include the template implementation file. Instead, the compiler
looks for a file with the same name as the template implementation
file and extension .c the first time it needs a particular
instantiation. If the compiler subsequently needs the same instantiation,
it uses the copy stored in the template include directory.
Note: You can also use
-qtemplateregistry that
provides more benefits than
-qtempinc, and does
not require modifications to your source files. For details, see
-qtemplateregistry (C++ only) in
the
XL C/C++ Compiler
Reference.