unique_ptr<int> a;
if (a) {
cout << "ASSIGNED" << endl;
}
,甚至这样的代码:
unique_ptr<int> a;
if (static_cast<bool>(a)) {
cout << "ASSIGNED" << endl;
}
原因这样的警告:
warning C4800: 'void (__cdecl *)(std::_Bool_struct<_Ty> &)' : forcing value to bool 'true' or 'false' (performance warning)
with
[
_Ty=std::unique_ptr<int>
]
在Visual Studio 2012上警戒线3.我发现的第一个评论后只有在公共语言运行时支持/ clr打开时才会发生。我应该如何避免它?
if (a.get() != nullptr)
应该工作,但我认为这不是如何设计unique_ptr,是吗?
我有VS2013,但它不给我这样的警告! – billz
在Visual Studio 2010中建立没有警告的级别警告设置为“/ W4”... – Johan
我正在编译/ W3(添加到帖子) –