Being a dll newbie I have to ask the allmighty SO about something.
Say I explicitly instantiate a template class like this:
template class __declspec(dllexport) B<int>;
How do I use import this templated class again?
I've tried the adding the code below in my .cpp file where I want to use B
template class __declspec(dllimport) B<int>;
It seems, even with explicit instatiation of the template, problems may arise that lead to run-time errors. Take a look at this interesting article to C4251 (especially the "Conclusion").
When you instantiate a template fully -- you have a complete type. It is no different from any other types. You need to include the header for
B
and also compile-time linking in with alib
file or dynamically load the dll to link to the definition.Have you read this article: http://support.microsoft.com/kb/168958 ?
Here's a brief summary of what I tested (and it worked):
Create a dummy DLL project
template_export_test
file:
template_export_test.h
file:
template_export_test.cpp
Create the test application
driver
template_export_test.lib
template_export_test.lib
template_export_test.h
in the main cpp file