以下的weak_ptr的構造函數的是2: http://msdn.microsoft.com/en-us/library/bb982126.aspx的weak_ptr的怪異的拷貝構造函數
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,那麼爲什麼不固定的縮進? – Motti