【发布时间】:2011-08-12 00:00:14
【问题描述】:
以下是两个weak_ptr 的构造函数: http://msdn.microsoft.com/en-us/library/bb982126.aspx
weak_ptr(const weak_ptr&);
template<class Other>
weak_ptr(const weak_ptr<Other>&);
实际代码(来自memory):
weak_ptr(const weak_ptr& _Other)
{ // construct weak_ptr object for resource pointed to by _Other
this->_Resetw(_Other);
}
template<class _Ty2>
weak_ptr(const weak_ptr<_Ty2>& _Other,
typename enable_if<is_convertible<_Ty2 *, _Ty *>::value,
void *>::type * = 0)
{ // construct weak_ptr object for resource pointed to by _Other
this->_Resetw(_Other);
}
Q1:为什么顶部的复制构造函数还在那里?看起来底部的一个占每个案例(包括顶部的一个)。它甚至被调用吗?如果他们不包括它,底部的会取代它吗?
Q2:底部(模板化)构造函数的第二个参数发生了什么。我想我了解 SFINAE 方面,但我不明白为什么::type 后面有一个额外的 *
【问题讨论】:
-
@Hans,那为什么不修复缩进呢?
标签: c++ c++11 shared-ptr weak-ptr