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

What is the function of the monocular operator overloaded by C++

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what is the function of the monocular operator overloaded by C++", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn the "C++ overloaded monocular operator what is the role of it?"

C.166: overloaded unary operator & can only be used for smart pointers and references

Reason (reason)

The address operator is the basic element of C++, and many parts of C++ semantics set the default meaning for it.

Example (sample)

Class Ptr {/ / a somewhat smart pointer

Ptr (X* pp): P (pp) {/ * check * /}

X* operator- > () {/ * check * / return p;}

X operator [] (int I)

X operator* ()

Private:

T * p

}

Class X {

Ptr operator& () {return Ptr {this};}

/ /...

}

Note (Note)

If you want to provoke the & operator, make sure its result type and->, [], * and. Match. Pay attention. Operators cannot be overloaded now, so it is not possible to achieve a perfect system.

Enforcement (implementation recommendations)

It's not easy. Alarm if the & operator is customized but the-> operator is not defined for the result.

At this point, I believe that everyone on the "C++ overloaded monocular operator what is the role of" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Internet Technology

Wechat

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

12
Report