如何访问其他班级的私人成员?

时间:2020-10-14 16:52:03

标签: c++ shared-ptr weak-ptr

我正在实现自己的SharedPtr和WeakPtr,有许多方法需要从WeakPtr的方法访问SharedPtr的私有成员。例如:

template<typename Resource>
WeakPtr<Resource>::WeakPtr(const SharedPtr<Resource>& rhs)
{
    //how can i get access to private members of rhs there?
    //only way is make them public?
    //I need something like this:
    resource = rhs.resource;
    control_block = rhs.control_block;
}

0 个答案:

没有答案
相关问题