C++ 11's std :: shared_ptr <>提供了一种布尔运算符。为什么std :: weak_ptr <>不提供布尔转换?
operator unspecified-bool-type() const;
(这不是一个直线上升operator bool() const
由于bool
类型的dangers from implicit casting)
为什么不的std :: weak_ptr的<>有类似的运营商?我发现自己经常打字
if(!wp.expired())
,当我想要键入
if(wp)
为什么没有布尔转换为weak_ptr的?
因为功能默认没有实现? – 2012-04-23 15:02:15
'operator bool'现在可以在C++ 11中直接安全地完成:http://stackoverflow.com/a/6242355/46642 – 2012-04-23 18:55:26