Are derived classes considered friends?

て烟熏妆下的殇ゞ 提交于 2020-01-02 05:06:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!