Template Compilation Model

Instantiations are treated as if they are defined in the file containing the definition of the template. The code will be generated in the corresponding target. In all other respects they behave just like normal classes and functions. A file with template definitions in it will generate code for all instantiations from all source files into the target corresponding to the source file containing the template definition..

If you don't want to have an instantiation generated in a specific target, then make sure that there are no template definitions in any of its files, either as sources or included files. Forward declarations will not cause templates to be instantiated so when they are used references will be resolved at link time.

Pragma define is implemented as explicit instantiation, which is implemented according to ANSI. Again, the target that will obtain the generated code for these instantiations is the target that is in effect for the source containing the template definition.

If we have multiple definitions for the templates in more than one target, we get exactly the same behavior as if we had the same function or class defined in multiple targets.

For more on templates, refer to Stroustrup, Chapter 13.