1
我在過去兩天里正在閱讀std::enable_shared_from_this
(g ++版本)源代碼。有兩個問題讓我困惑。
讓我先顯示簡要的源代碼。模板好友功能重載
template<typename _Tp>
class enable_shared_from_this {
...
private:
template<typename _Tp1>
friend void
__enable_shared_from_this_helper(const __shared_count<>& __pn,
const enable_shared_from_this* __pe,
const _Tp1* __px) noexcept {
}
};
template<typename _Tp1, typename _Tp2>
void
__enable_shared_from_this_helper(const __shared_count<>&,
const enable_shared_from_this<_Tp1>*,
const _Tp2*) noexcept;
問題:
1.注意行const enable_shared_from_this* __pe
,沒有標記 '<>' enable_shared_from_this
後,這是否意味着這裏enable_shared_from_this<__Tp1>
?
2.這裏有兩個超載函數模板__enable_shared_from_this_helper
,我的測試顯示在class enable_shared_from_this
中定義的版本會永遠被調用,爲什麼?
謝謝你們,我將不勝感激。