std::string在Visual Studio 2010中给出编译器警告
std::string gives compiler warning in Visual Studio 2010
我正在将Visual Studio 2005的c++代码迁移到Visual Studio 2010。不幸的是,我在VS2010上得到std::string错误,而在VS2005中,我以前从未有过此错误。
下面是代码示例#include<string>
typedef std::string String
class __declspec(dllexport) SomeClass
{
public:
String somevariable; // compiler warning here. Please see below for the compiler warning.
void SomeFunction(String sName); // No compiler errors or warning here
};
编译器警告:
error C2220: warning treated as error - no 'object' file generated
warning C4251: 'SomeClass::somevariable' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'SomeClass'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
请帮忙给我解决这个问题的方法
我建议先阅读并理解Arun给出的链接。然后,如果您可以合理地确定您没有使用不同的编译器(这在c++中无论如何都是导致灾难的原因),您可以简单地禁用/忽略警告。
顺便说一句:
- 对于某些代码,我从VS2005中得到相同的警告。你完全正确,这种行为是不一致的。函数和成员变量要么都触发诊断,要么都不触发。
相关文章:
- 如何修复编译器警告 C6386 和 C6385?
- 编译器警告:执行到达值返回函数的末尾而不返回值
- 为什么布尔开关语句有编译器警告?
- 奇怪的缩小转换在 g++ 编译器中加倍到浮点警告
- 处理编译器关于可能丢失数据的警告的最优雅方法是什么
- 使用 reverse_iterator 而不是const_reverse_iterator并获得讨厌的编译器警告和错误
- 添加 c++11 编译器后打开 devc++ 时显示的警告
- 来自 std::chrono 的编译器警告,但未被使用
- 警告级别为 3 的 int 的 std::vector push_back 处的编译器警告
- G++ 编译器未为未定义的方法生成错误/警告
- 从 int 中剥离位时,编译器会警告一个转换,但不警告其他转换.有解决方法吗?
- 有没有办法在从临时返回按值string_view时获得编译器警告?
- 常量更改而不const_cast<> 为什么没有编译器警告/错误?
- 为什么编译器不在同一翻译单元中警告 ODR 违规
- C++语法错误,编译器不会警告或 int v = func(&v) 出错;
- C++ 添加编译器警告,以错误使用自定义打印/日志功能
- 我正在尝试在我的类中创建一个静态成员,但编译器警告我它是未定义的
- 是否可以将移动的变量标记为不再可用,并在使用它时收到编译器警告?
- 为什么我应该始终启用编译器警告
- 使用Boost :: black在boost :: variant中使用时,请警告编译器