简体   繁体   中英

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?

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.

No it isn't.

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

Friendship is neither inherited nor transitive.

不,不是,如此处所述: http//www.parashift.com/c++-faq-lite/friends.html#faq-14.4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM