Description
There are a couple of common ways to organize template source code. One is to place the template declaration and definition in a header file, and include the headers in each compilation unit. The Standard Template Library uses this approach. This scheme has a couple of drawbacks, however, in that the same definitions are processed over and over, and user code may come to depend on information found in the template header that is placed there only for the benefit of the template definitions.
Another approach is to simply #include only template declarations, and then compile the template definitions one time in a separate compilation unit. The export keyword in C++ is used to facilitate this process. The idea is to declare templates (typically via a header file) in whatever compilation units need them, and then place the template definitions in a separate compilation unit, prefacing each definition with export.
Concept
In the sample program, file2.cpp defines a class template A and a function template findmin(). Their definitions are exported. file1.cpp declares these templates via a header file and uses them, and the instantiation process matches up the uses in one compilation unit with the exported definitions in the other.
Special Notes:
See also the _Export keyword and #pragma export(), for other ways of exporting C++ symbols.
Supported
Supported
Supported
