tunnuz
tunnuz

Reputation: 24028

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?

Upvotes: 14

Views: 2247

Answers (3)

anon
anon

Reputation:

No it isn't.

Edit: To quote from the C++ Standard, section 11.4/8

Friendship is neither inherited nor transitive.

Upvotes: 9

Daniel Bruce
Daniel Bruce

Reputation: 11547

No it isn't, as documented here: http://www.parashift.com/c++-faq-lite/friends.html#faq-14.4

Upvotes: 7

simplyharsh
simplyharsh

Reputation: 36383

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.

Upvotes: 19

Related Questions