以下是两个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