Search code examples
c++inheritancefriendaccess-control

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?


Solution

  • 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.