[英]Access a class' private members?
So I have parent class A. Classes B and C inherit from A, however they do not relate to each other.所以我有父类 A。类 B 和 C 从 A 继承,但是它们彼此不相关。 Classes B and C both define their own private members.
类 B 和 C 都定义了它们自己的私有成员。 How can class C access class Bs private members, without inheriting from it ?
C 类如何访问 B 类的私有成员而不继承它?
You have to declare C
as a friend
of B.您必须声明
C
为 B 的friend
。
class B{
friend class C;
// ....
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.