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

问题描述

我正在实现自己的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;
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)