禁用警告 C4251:“...需要有 dll 接口供类的客户端使用...”

Ser*_*tch 5 c++ dll templates stl compiler-warnings

我正在尝试解决警告 C4251:“...需要有 dll 接口供类的客户端使用...”对于 STL 类,比将使用 STL 的每个类与#pragma warning( push )和包装在一起#pragma warning( disable : 4251 ),然后#pragma warning( pop ).

因此,为了实现这一点,我尝试从 STL 模板中导出任何可以导出的内容,如下面的代码。但是,有一些私有的嵌套 STL 类我无法以这种方式导出。所以我仍然需要将公共 STL 类的导出块包装到禁用警告的代码中:

#ifdef SRPLATFORM_EXPORTS
#define SRPLATFORM_API __declspec(dllexport)
#else
#define SRPLATFORM_API __declspec(dllimport)
#endif // SRPLATFORM_EXPORTS

#pragma warning( push )
#pragma warning( disable : 4251 ) // needs to have dll-interface to be used by clients of class
class SRPLATFORM_API std::exception_ptr;
template struct SRPLATFORM_API std::atomic<int32_t>;
class SRPLATFORM_API std::thread;
template SRPLATFORM_API class std::allocator<std::thread>;
template class SRPLATFORM_API std::vector<std::thread>; // this is line 19 in my file
#pragma warning( pop )
Run Code Online (Sandbox Code Playgroud)

但是,我仍然为嵌套的私有 STL 类获取 C4251:

1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\include\vector(701): warning C4251: 'std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>::_Mypair': class 'std::_Compressed_pair<std::_Wrap_alloc<std::allocator<std::thread>>,std::_Vector_val<std::_Simple_types<std::thread>>,true>' needs to have dll-interface to be used by clients of class 'std::_Vector_alloc<std::_Vec_base_types<_Ty,_Alloc>>'
1>        with
1>        [
1>            _Ty=std::thread,
1>            _Alloc=std::allocator<std::thread>
1>        ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\include\vector(680): note: see declaration of 'std::_Compressed_pair<std::_Wrap_alloc<std::allocator<std::thread>>,std::_Vector_val<std::_Simple_types<std::thread>>,true>'
1>d:\dev\views\engines\probqa\srplatform\../SRPlatform/Interface/SRPlatform.h(19): note: see reference to class template instantiation 'std::vector<std::thread,std::allocator<std::thread>>' being compiled
Run Code Online (Sandbox Code Playgroud)

那么我是否必须将 include 语句(如#include <vector>)包含在禁用警告的语句中?或者,有人可以澄清发生了什么吗?