In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to avoid the same type of irrelevant parameters adjacent". In the operation of practical cases, many people will encounter such a dilemma. Then 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!
Avoid adjacent Reason of the same type of irrelevant parameters (reason)
Contiguous parameters of the same type can be easily reversed.
Example, bad (negative example)
Consider (consider the following code):
Void copy_n (T * p, T * Q, int n); / / copy from [pvl p + n) to [Q v Q + n)
This dangerous variant of the Krypr C-style interface. It is easy to reverse the to and from parameters.
Use const modification for the from parameter.
Void copy_n (const T* p, T* Q, int n); / / copy from [PVV p + n) to [QRV Q + n)
Translator's note: if the from buffer is of type const, reversing the parameter will result in a compilation error.
Exception (exception)
If the order of the parameters is not important, there is no problem:
Int max (int a, int b); Alternative (optional)
Instead of passing an array as a pointer, pass an object that represents range (such as span):
Void copy_n (span p, span Q); / / copy from p to qAlternative (optional)
Define a structure for the parameter type and name the field according to the parameter:
Struct SystemParams {string config_file; string output_path; seconds timeout;}; void initialize (SystemParams p)
Because parameters are usually assigned by the caller according to the name, this will help future readers to call the function more explicitly.
Enforcement (implementation recommendations)
(simple) if there are two consecutive parameters of the same type, alarm.
This is the end of the content of "how to avoid adjacency of the same type of irrelevant parameters in C++". Thank you for 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.