问题
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?
Thanks
回答1:
struct A{};
struct Ader : A{};
struct B{
friend struct A;
};
No. Friendship is not inherited in 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
.
回答2:
No, that's not allowed. Check here.
来源:https://stackoverflow.com/questions/4083838/are-derived-classes-considered-friends