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
中定义的版本会永远被调用,为什么?
谢谢你们,我将不胜感激。