[英]Are derived classes considered friends?
If I create base class A and A is a friend of class B, can a class derived from A access B to its liking, or else what is it allowed? 如果我创建基类A而A是B类的朋友,那么一个类可以从A访问B派生出来,或者它允许什么?
Thanks 谢谢
struct A{};
struct Ader : A{};
struct B{
friend struct A;
};
No. Friendship is not inherited in C++. 不。友谊不是在C ++中继承的。 It is also not transitive.
它也不是传递性的。
Ader
can not access B
as a friend unless explicitly given friendship by B, just because it's base A
is a friend of B
. 除非
B
明确给予友谊,否则Ader
不能作为朋友访问B
,因为它的基础A
是B
的朋友。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.