dllexport template class

I'm using VS2015 and have written a DLL that exports a template class:

1
2
3
4
5
6
7
8
9
10
11
12
#ifdef MYDLL_EXPORTS
#define MYDLL_API __declspec(dllexport)
#else
#define MYDLL_API __declspec(dllimport)
#endif

template <class T> class MYDLL_API CFoo
{
public:
   CFoo();
   ...
};


This compiles fine, but when I attempt to use the templated class in a test program, I get a LNK2019 unresolved external symbol.

Surely this must be possible, as the std library must do this? I would appreciate if anyone could advise on what must be done to get this to work.

Last edited on
A template will only be compiled with spedified template parameter. Thus there will be nothing in the dll to link against.

In order to use a template you always need to include both: declaration and definition. You cannot put the definitions in a .cpp file like ordinary classes/functions.
Topic archived. No new replies allowed.