C++中的友谊是继承的吗? [英] Is friendship inherited in C++?
本文介绍了C++中的友谊是继承的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个 Base
类:
class Base {
friend SomeOtherClass;
};
还有另一个(不同的)类继承自 Base
:
And there is another (different) class that inherits from Base
:
class AnotherClass : public Base {}
友谊也是遗传的吗?
推荐答案
原则上,派生类继承基类的每个成员,除了:
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.
这篇关于C++中的友谊是继承的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文