Monday, December 20, 2004

C++ Template Compilation Model

Inclusion Model: Complete source code for Template functions will be available in the header files. This is because, the template functions are compiled at the user end for a type specified by the user. This need source code for the template function, hence all the template functions are always included in the header file itself. This is the only portable way available. Most STL libraries are available in header files. Alternately, the functions will be defined in a source file and the source file will be included in the headerfile ( achieves partial seperation of interface from implementation), but still the code in these source file will be compiled only at the user end. Major problem, not for all, is that source is exposed.

Export Model or Seperation Model: To avoid this problem of templates having to be present in the headerfiles, the C++ standard introduced a template compilation model with a keyword "export". But looks like, this has not been successfully implemented so far. Add "export" as qualifier to either the template declaration or definition to use the feature. However, most of the available versions of compilers still need full source code to be shipped to the users, and seems there are still a few other issues.

One issue with using export is illustrated at

Export Restrictions, C/C++ Users Journal, 20(9), September 2002 (
) : Fact or Allegation ? Just another twisted title for sensationalism

This is yet another example of’s sensationalism twisted titles. The title says, as if this was a fact, woman made to urinate in pub...