In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 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 "when does C++ use the original pointer". 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!
R.2: only means that individual objects use the original pointer in the interface
Reason (reason)
Arrays are best represented by container types (for example, vector (with ownership) or span (without ownership). The container or span contains information that can be used for range checking.
Example, bad (negative example)
Void f (int* p, int n) / / n is the number of elements in p []
{
/ /...
P [2] = 7; / / bad: subscript raw pointer
/ /...
}
The compiler doesn't read comment lines, and you can't know that p actually points to n elements without looking at other code. Use span.
Example (sample)
Void g (int* p, int fmt) / / print * p using format # fmt
{
/ /... Uses * p and p [0] only...
}
Exception (exception)
A C-style string is passed as a pointer to a sequence of characters ending in 0. Use zstring instead of char* to show that you follow this habit.
Note (Note)
Many current pointers to individual features can use references. However, a reference is not a reasonable choice when nullptr is also a valid value.
Enforcement (implementation recommendations)
Prompt if a pointer does not come from a container, view, or iterator and there is a pointer operation (including +). If this rule is applied to old code, it will produce a large number of false positive results.
Prompts you to pass the array with the original pointer.
This is the end of the content of "when does C++ use the original pointer"? 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.