1.26. Using Exported Templates
Problem
You want to build a
program that uses exported templates, meaning that it
declares templates in headers with the export keyword
and places template implementations in .cpp
files.
Solution
First, compile the .cpp files containing the template implementations into object files, passing the compiler the command-line options necessary to enable exported templates. Next, compile and link the .cpp files that use the exported templates, passing the compiler and linker the command-line options necessary to enable exported templates as well as the options to specify the directories that contain the template implementations.
The options for enabling exported templates are given in Table 1-39. The options for specifying the location of template implementations are given in Table 1-40. If your toolset does not appear in this table, it likely does not support exported templates.
Table 1-39. Options to enable exported templates
Table 1-40. Option to specify the location of template implementations
|
Toolset |
Script |
|---|---|
|
Comeau |
—template_directory=<path> |
|
Intel (Linux) |
-export_dir<path> |
For example, suppose you want to compile the program displayed in Example 1-27. It consists of three files:
The file plus.hpp contains the declaration of an ...