Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

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

Shulou Source: shulou.com Published: 2022-06-01 19:18:25 09月30日 Update

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!

Tags: Operator operation caching action content result learning practical deeper interest reason meaning address place practicality practice suggestion pointer simple operation method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Apple Shulou Information Xiaomi Shulou Tech Info