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?
Classes which are marked as sealed at time of definition can not be inherited. Sealed classes cannot be inherited. Class that are marked with the sealed (C#) or NotInheritable (VB.NET) keywords cannot be inherited from. This is done at the definition of the classes.
The privileges of friendship aren't transitive. A friend of a friend isn't necessarily a friend.
In C++ we can define a parent child relationship between classes in such a way that child class will inherit all the attributes of its parent class plus it will have its own attributes and functions. Inheritance is based on the principle of is-a relationship.
friend is a keyword in C++ that is used to share the information of a class that was previously hidden. For example, the private members of a class are hidden from every other class and cannot be modified except through getters or setters.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With