In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to implement citation merge 11". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Actual parameter inference
Consider the following template function and calling code.
For the first two cases, the compiler can simply judge the parameter types as integers and floating-point numbers according to the type of input; in the third case, the compiler cannot find a reasonable explanation for const char* times 2, so the result is a compilation error.
Type inference of left value reference parameter
Things get a little more complicated if the parameter type is a left-value reference. For example, the following code.
For the above template function, the following code can be compiled normally.
The reason, of course, is that parameter type inference can be done correctly. For example, when the actual parameter type is int, the template parameter can be understood as:
Type inference of right value reference parameter
With the introduction of right-value references in Category 11, programmers can define the following template functions.
For this template function, the following invocation methods are legal because the arguments are all right values.
What if, like the following code, the argument is a reference type?
In order to see more clearly, this follows the method brought in by the previous type. when T is int&, f3 looks like this:
Notice the section on the red line, which refers to another new feature of Clippers 11. When a reference and a right value reference appear at the same time, follow the following principles:
Left reference + left reference = left reference
Left value reference + right value reference = left value reference
Right value reference + left value reference = left value reference
Right value reference = right value reference
To sum up, the principle is simple: always give priority to the left value. This is called reference merging (reference collapse).
According to the above principles, the code can be deformed again:
The following are the results of the implementation:
After f3 executes, the value of lf becomes 10.
This is the end of the content of "citation 11 reference merge". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.