std::vector needs to have dll-interface to be used by clients of class #39;Xlt;Tgt; warning(std::vector 需要具有 dll 接口以供类 Xlt;Tgt; 的客户端使用.警告)
问题描述
我正在尝试将我的库作为 DLL 导出,但我收到了很多针对使用 std::vector 的特定类的警告:
I'm trying to make my library exportable as a DLL but I'm getting a lot of these warnings for one specific class that uses std::vector:
template <typename T>
class AGUI_CORE_DECLSPEC AguiEvent {
typedef void (*AguiCallbackFptr)(T arg, AguiWidget* sender);
std::vector<AguiCallbackFptr> events;
public:
void call(AguiWidget* sender, T arg) const;
void addHandler(AguiCallbackFptr proc);
void removeHandler(AguiCallbackFptr proc);
void removeHandler();
AguiEvent();
};
我收到如下警告:
警告 57 警告 C4251:'AguiEvent::events' : 类'std::vector<_Ty>' 需要有客户端使用的 dll 接口类'AguiEvent'
Warning 57 warning C4251: 'AguiEvent::events' : class 'std::vector<_Ty>' needs to have dll-interface to be used by clients of class 'AguiEvent'
我试图找到如何正确执行此操作,但 MSDN 的文档仅适用于 Windows,并且我需要它是跨平台的,以便在实际定义 AGUI_CORE_DECLSPEC 时仅执行 MS 特定的操作.
I tried to find how to do this properly but MSDN's documentation is very Windows Only, and I need this to be cross platform so that it only does MS specific stuff when AGUI_CORE_DECLSPEC is in fact defined.
我应该怎么做才能消除这些警告?
What should I do to get rid of these warnings?
谢谢
推荐答案
从 DLL 导出是特定于平台的.您必须为 Windows 修复此问题(基本上使用 declspec(dllexport/dllimport) 在实例化的类模板上)并将所需的代码封装在 Windows 特定的预处理器宏中.
Exporting from a DLL is platform-specific. You will have to fix this for Windows (basically use declspec(dllexport/dllimport) on the instantiated class template) and encapsulate the required code in your Windows-specific preprocessor macro.
我的经验是,从 Windows 上的 DLL 导出 STL 类充满痛苦,通常我会尝试设计不需要的接口.
My experience is that exporting STL classes from DLLs on Windows is fraught with pain, generally I try to design the interface such that this is not needed.
这篇关于std::vector 需要具有 dll 接口以供类 'X<T> 的客户端使用.警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:std::vector 需要具有 dll 接口以供类 'X<T> 的客户端使用.警告
基础教程推荐
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
