• Advertisement
Sign in to follow this  

Putting template object-code inside a library

This topic is 3513 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I have some tools (parsers etc) that work off std::basic_string<T>. 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<char>::~parser() etc. If I stick:
template <typename T>
class parser {
    // etc...

#include "PUBLIC-HEADER"
template <typename T>
parser<T>::~parser() {
    // do delete stuff.

template <>

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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement