In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains why C++ becomes a member only by directly visiting the expressed function. Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn why C++ becomes a member only by directly accessing the expressed function.
C.4: only by directly accessing the expressed function should you become a member.
Reason (reason)
Compared with the use of member functions, the coupling of ordinary functions is slightly lower. On the one hand, fewer functions can cause trouble by modifying the state of the object, on the other hand, it can reduce the number of functions that need to be modified when changing the class expression.
Example (sample)
Class Date {/ /... Relatively small interface...}
/ / helper functions:Date next_weekday (Date)
Bool operator== (Date, Date)
The "helper functions" have no need for direct access to the representation of a Date.
There is no need for the "help function" to access the Data expression directly.
Note (Note)
This rule becomes even better if C++ gets "uniform function call".
It would be even more perfect if C++ could import the rule of "unified function calls".
Translator's note: "uniform funcation call" is a C++ grammar suggestion put forward by the father of C++ himself. The core is that for a function call in the form of f (xrecoery y), if there is no function f (xperiary y), you can call x.f (y) instead. With this syntax, the flexibility of writing non-member helpers will be further increased.
Exception (exception)
(C++) the language requires that virtual functions must be members, and not all virtual functions access data directly. In general, members of abstract classes rarely access data directly.
Note multi-methods.
Exception (out of class)
The language requires operators =, (), [], and-> to be members.
The language requires the =, (), [] and-> operators to exist as members.
Exception (not listed)
An overload set may have some members that do not directly access private data:
A member of a set of overloaded functions may not directly access private data.
Class Foobar {public: void foo (long x) {/ * manipulate private data * /} void foo (double x) {foo (std::lround (x));} /... private: / /.}
Exception (exception)
Similarly, a set of functions may be designed to be used in a chain:
Similarly, a set of functions may be designed to be used in series.
X.scale (0.5). Set_color (Color::red)
Typically, some but not all of such functions directly access private data.
In general, some but not all of these functions access private data directly
Enforcement (implementation recommendations)
Look for non-virtual member functions that do not touch data members directly. The snag is that many member functions that do not need to touch data members directly do.
Look for non-virtual member functions that do not have direct contact with data members. Ironically, there are many member functions that do not require direct access to data members.
Ignore virtual functions.
Ignore virtual functions.
Ignore functions that are part of an overload set out of which at least one function accesses private members.
If at least one function in a set of overloaded functions accesses private members, the other functions are ignored.
Ignore functions returning this.
Functions that return this pointers are ignored.
At this point, I believe you have a deeper understanding of why C++ becomes a member only by directly accessing the expressed functions. You might as well do it in practice. 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.