Re: Are std::list and std::map safe to export?
On Sun, 16 Jul 2006 00:24:16 -0400, matthew breedlove <sirmalloc@gmail.com>
wrote:
Thanks for the quick response. If I happened to be exporting my own
template class, would the following be the appropriate way to handle this?
//In the project exporting the class
template class __declspec(dllexport) MyTemplateClass<int>;
//In the project referencing the DLL
extern template class __declspec(dllimport) MyTemplateClass<int>;
Yes, but see this KB article for more:
http://support.microsoft.com/kb/q168958/
In particular, note the use of the DECLSPECIFIER and EXPIMP_TEMPLATE
macros. You should use them but rename them according to your DLL name,
controlling their expansion with another macro also keyed to your DLL name,
e.g. COMPILING_X_DLL, where X is the name of your DLL. This will allow your
DLL to use other DLLs that use the same technique and vice versa.
And secondly, if my own template class uses static data, are you saying
that I'll have to have a separate DLL export it using the above method?
The problem with template static data and multiple modules is that the
static data is instantiated in every module that uses it, so instead of
there being exactly one instance of the data in the program, there are
multiple instances. To avoid this problem, you need to instantiate and
export the template in one module that all the others use.
--
Doug Harrison
Visual C++ MVP