禁用警告C4251:" ...需要让dll-interface供班级客户使用..."

时间:2017-07-20 11:55:16

标签: c++ templates dll stl compiler-warnings

我正在尝试解决警告C4251:" ...需要让dll-interface供班级客户使用..."对于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 )

但是,我仍在为嵌套的私有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

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

0 个答案:

没有答案
相关问题