C + +-friend friend can inherit? __c++

Source: Internet
Author: User

a friend cannot be inherited: that is, a friend of a base class may not be a friend of a subclass, and a subclass of a friend of a type may not be a friend of this type. in detail, you can look at the following two sections:

What does it mean that "friendship isn ' t inherited, transitive, or reciprocal"?

Just because I grant you friendshipAccessTo me doesn ' t automaticallygrant your kidsAccessTo me, doesn ' t automatically grant your friendsAccessTo me, and doesn ' t automatically grant meAccessTo you. I don ' t necessarily trust the kids's my friends. The privileges offriendship aren ' t inherited.DerivedClasses of afriendAren ' t necessarilyfriends. IfclassFred declares that.class Baseis afriend, classesderivedFromBaseDon ' t have any automatic specialAccessRights tofred objects. I don ' t necessarily trust the friends's my friends. The privilegesof friendship aren ' t transitive. Afriendof afriendisn ' t necessarily afriend. IfclassFred declaresclassWilma as afriend, andclassWilma declaresclassBetty as afriend,classBetty doesn ' tnecessarily have any specialAccessRights to Fred objects. Don ' t necessarily trust me simply because I declare for youfriend. The privileges of Friendship aren ' t reciprocal. IfclassFreddeclares thatclassWilma is afriend, Wilma objects have specialAccessTo Fred Objects but Fred objects does not automatically have specialAccessTo Wilma objects. (http://www.parashift.com/c++-faq-lite/friends.html)

What is inherited from the base class?
In principle, a derived class inherits every member of a base class except:

Its constructor and its destructor its operator= (), its friends (http://www.cplusplus.com/doc/tutorial/ inheritance/)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.