Skip to main content
gamedev.net
🔒 Locked

Putting template object-code inside a library

Started by yacwroy Jul 13, 2008 at 7:18 AM 0 replies 600+ views
Original Post
yacwroy
yacwroy
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:

// 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();

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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.