Getting rid of dllimport warning messages for template classes
Posted on 2004-08-20
I'm tired of stuff like this:
// File: foo.h
class __declspec(dllimport) foo
When including foo.h you will get a bunch of warnings about vector<> (or it's allocator) not being dllexported:
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\vector(35) : warning C4251: 'std::_Vector_val<_Ty,_Alloc>::_Alval' : class 'std::allocator<_Ty>' needs to have dll-interface to be used by clients of class 'std::_Vector_val<_Ty,_Alloc>'
Of course, vector isn't dllexported because it is a template class, and its implementation is entirely contained within the relevant header files. Is there some way to avoid these warning?
Unacceptable solutions are:
(1) using #pragma warning(disable: xxxx) or similar to simply surpress the errors
(2) changing any of the standard header files
(3) Changing the dllexport nature of the client class (foo), for example by only exporting specific functions