Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is friendship inherited in C++?

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?

like image 397
tunnuz Avatar asked Feb 28 '09 10:02

tunnuz


People also ask

Which Cannot be inherited in C?

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.

Is friendship transitive in C++?

The privileges of friendship aren't transitive. A friend of a friend isn't necessarily a friend.

Is a relationship in C++ inheritance?

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.

Is friend a keyword in C?

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.


1 Answers

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.

like image 90
simplyharsh Avatar answered Nov 15 '22 20:11

simplyharsh