Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to apply C++ friend and operator overloading

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to apply C++ friends and operator overloading". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought. Let's study and learn how C++ friends and operators overload.

Friendly yuan

In life, your home has a living room (Public) and your bedroom (Private). All guests in the living room can enter, but your bedroom is private, that is to say, only you can enter, but you can also allow your best friend and gay friend to enter.

In the program, some private properties also want to be accessed by some special functions or classes outside the class, so they need to use friend technology.

The purpose of friends is to allow one function or class to access private members of another class.

The keyword of friend is: friend

There are three implementations of friends:

Global function as friend

Class as friend

Member functions as friends

1 the global function friend class Building {/ / tells the compiler that the global function is a good friend of the Building class and can access the private content friend void goodGay (Building * building) in the class; public: Building () {this- > m_SittingRoom = "living room"; this- > m_BedRoom = "bedroom";} public: string m_SittingRoom / / living room private: string masked BedRoom; / / bedroom}; void goodGay (Building * building) {cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report