Are derived classes considered friends?

If I create a base class A and A is a friend of class B, can the class derived from A access B be to my liking, or is it allowed?

thank

+5
source share
2 answers
struct A{};

struct Ader : A{};

struct B{
   friend struct A;
};

No. Friendship is not inherited in C ++. It is also not transitive.

Adercannot access Bas a friend unless explicitly indicated by friendship on B, simply because the base Ais a friend B.

+8
source

No, this is not allowed. Check here .

+1
source

All Articles