Original Post
Hi. I have some tools (parsers etc) that work off std::basic_string. I want to build libraries for these tools for specific versions of T. eg parser.char.a, parser.wchar_t.a etc... However, I can't figure out how to create a source file that will contain the object-code for say parser::~parser() etc. If I stick: Note: Those aren't my actual filenames. C++ just treats the code in LIBRARY-BUILDING-SOURCE as a declaration. The only ways I know to force the issue are: 1: To make a function inside the library-building source that calls all of the specific template functions, and prevent them from being auto-inlined. 2. To specialize the template in LIBRARY-BUILDING-SOURCE by using a #define or typedef to select the variable. Is there a better way? Thanks.
// PUBLIC-HEADER:
template <typename T>
class parser {
~parser();
// etc...
}
// LIBRARY-BUILDING-HEADER:
#include "PUBLIC-HEADER"
template <typename T>
parser<T>::~parser() {
// do delete stuff.
}
// LIBRARY-BUILDING-SOURCE
#include "LIBRARY-BUILDING-HEADER"
template <>
parser<char>::~parser();