友谊在C ++中继承吗? [英] Is friendship inherited in C++?
本文介绍了友谊在C ++中继承吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个 Base
类:
class Base {
friend SomeOtherClass;
};
还有另外一个不同的类继承自 Base
:
class AnotherClass:public Base {}
$
解决方案原则上,派生类继承基类的每个成员,除了:
*其构造函数及其析构函数
* )member
*其朋友
朋友不会继承。
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?
解决方案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屋!
查看全文