c++templatesdistributionconstruction

Cross source file template instantiation and use


I have a class with several template member functions that I would like to distribute among several source files to speed up compilation times. (The templates are implementation details and are not intended to be used outside the class, hence their definition in sources not headers.)

How would I go about splitting up these templates in such a way that I will not get linker errors? If I have source file A using a template defined in source file B, how do I make sure the appropriate instance of the template is constructed by the compiler?


Solution

  • I could not answer it better than C++ FAQ:
    https://isocpp.org/wiki/faq/templates#templates-defn-vs-decl