0

I have just made the experience that variadic classes dont seem to work too well when compiling a static library in Visual Studio?

I have someting like this:

template <typename ...T>
class A {...};

class B : public A<std::string> {...};

The linker wont put everything together, when I test my static library I get unresolved external symbol errors for the methods that I use within B that come from A. When I remove the variadic template and specialize the class myself (providing different implementations of the same class) everything works fine.

Am I doing something wrong or is visual studio having problems here?

Constructor
  • 7,273
  • 2
  • 24
  • 66
user2276094
  • 399
  • 1
  • 4
  • 11
  • The definition of a template must be visible in the translation unit in which it is instantiated (which usually means your code in the header file), or it must be explicitly instantiated for the desired types. That is simply how C++ templates work. Is your definition in the header? – Dark Falcon May 01 '14 at 17:13
  • I have one header file with the class definition and one cpp with the implementation of the methods. – user2276094 May 01 '14 at 17:46
  • 1
    As noted, the implementation must be visible in the TU where the template is instantiated. That means your implementation needs to move to the header, or you need to explicitly instantiate every possible instantiation you will be using. – Dark Falcon May 01 '14 at 17:50
  • possible duplicate of [Why can templates only be implemented in the header file?](http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file) – Casey May 02 '14 at 00:07
  • yep seems like thats it, are you a bot or how did you find that? – user2276094 May 02 '14 at 21:42

0 Answers0