warning C4251: 'm_Addrs' : class 'std::vector<class CAddr
*,class std::allocator<class CAddr *> >' needs to have dll-
interface to be used by clients of class 'CAddrList'
Because the member variable is private, I don't see why
the compiler would care about it being "used by clients of
class CAddrList". But, considering that that is the case,
I don't know how I would instantiate a template class and
declare it as part of a DLL interface (using __declspec
(dllexport)).
Does anyone understand this enough to explain it and solve
it?
Doug Sauder
You might try exporting the specializations you need, but the problem
with that, of course, is that you're probably always needing new
specializations. You can also try ensuring that no inline member
functions use the member provoking the C4251. This includes
compiler-generated default ctor, copy ctor, dtor, and assignment
operator, if any. The member in question is private, so the compiler
could assume that if no inline functions use it, and the class has no
friends, client context doesn't have access to it. But I don't know if
that helps, because I always disable this warning, which is usually
spurious. The compiler will instantiate the template when compiling
code that uses it (the "clients"), so if you don't mind each
dynamically linked component having its own copy of the generated
template code, you should be fine. If you would like to share one copy
among all the dynamically linked components, you'll need to explicitly
instantiate the specializations you need and export them from some
common DLL everybody links to. For example, this is what MS does with
basic_string<char>, basic_string<wchar_t>, and other specializations,
which you'll find in msvcp60.dll.