If there is a common definition of the template in the header file, and the header file is contained in multiple places, multiple compiled copies of the template will be created. This is certainly possible, but in large programs with multiple templates, all target files contain copies of each compiled template, which makes the compilation time very long and the target file is large,
Here are some optional scenarios:
1, in the source file, using the indicator Word #pragma interface and #pragma implementation, will only create a compiled template.
2, similar to the use of two Prama, use the command line option-falt-external-templates compile all the source files. This tells the compiler to include the compiled template instance only when the module is actually used. An important feature of this approach is that the header files must be the same for each module that uses the head file.
3. Compile the code with the command-line option-frepo, so that the file suffix created is. RPO, and each. rpo file lists the template instances in the corresponding destination file. The Connection Pack tool Collect2 is then activated to update the. rpo file, which instructs the connector to replace the template instance in the last program. This approach is only difficult when working with libraries---unless the associated. rpo files are present, the template instances in the connection library will fail.
4, compile the code with-fno-implicit-templates, will make the implicit template instantiation invalidation, he will display the initialization of the required template. While this approach requires a precise understanding of which template instance is being used, this approach does make the source code clearer.
Compile template instantiation