tags:

views:

846

answers:

3

I have a dll that contains a templated class. Is there a way to export it without explicit specification?

+3  A: 

Since the code for templates is usually in headers, you don't need to export the functions at all. That is, the library that is using the dll can instantiate the template.

This is the only way to give users to freedom to use any type with the template, but in a sense it's working against the way dlls are supposed to work.

James Hopkin
Here's some documentation on how to export template classes:http://support.microsoft.com/kb/168958
Laserallan
+1  A: 

When the compiler finds an instantiation of a template class, like MyTemplate<int>, then it generates the code for the template specialization.
For this reason, all the template code must be placed in an header file and included where you want to use it.
If you want to 'export' your template class, just place your code in an header file and include it where it's needed.

Paolo Tedesco
+1  A: 

Are you looking into exporting an instantiation of a template class through a dll? A class along the lines:

typedef std::vector<int> IntVec;

There is some discussion how to do this on: http://support.microsoft.com/kb/168958

Another approach is to explicitly exporting each function you are interested in through a wrapper class working against this template instance. Then you won't clutter the dll with more symbols than you are actually interested in using.

Laserallan