Is friendship inherited in C++?

那年仲夏 提交于 2019-12-03 17:11:42

问题


Suppose I have a Base class:

class Base {
    friend SomeOtherClass;
};

And there is another (different) class that inherits from Base:

class AnotherClass : public Base {}

Is friendship inherited as well?


回答1:


In principle, a derived class inherits every member of a base class except:

* its constructor and its destructor
* its operator=() members
* its friends

So, no. Friends are not inherited.




回答2:


No it isn't.

Edit: To quote from the C++ Standard, section 11.4/8

Friendship is neither inherited nor transitive.




回答3:


No it isn't, as documented here: http://www.parashift.com/c++-faq-lite/friends.html#faq-14.4



来源:https://stackoverflow.com/questions/597857/is-friendship-inherited-in-c

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