In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you what the C++ function template non-type parameters pay attention to, the content is concise and easy to understand, absolutely can make your eyes bright, through the detailed introduction of this article, I hope you can get something.
Template application in C++ programming language is a very important application technology. So today, let's first understand some basic concepts about the untyped parameters of the C++ function template, which is easy for you to understand.
C++ function template untyped parameters are mainly used to provide an operation constant for the function. With regard to untyped function template parameters, there are the following examples:
/ / function template definition template T addValue (T const& x) {return x + VAL;} / / other code / / the use of function templates std::transform (source.begin (), source.end (), dest.begin (), (int (*) (int const&)) addValue)
A function template is defined in the above code to add a specified int of 5 to the passed parameter. Such functions are commonly used in situations where a group of data is processed at the same time. For example, 12 lines. It should be noted here that a std::transform function itself is a template function, and its * parameter can pass a function pointer.
Therefore, the (int (*) (int const&)) addValue is actually a pointer to the instantiated addValue template function. As for how to read this pointer, please give me some advice. It is also important to note that a parameter of std::transform does not have to be a template function. Any function can (for a correct understanding of std::transform, refer to the comments below). It's just that template functions are more suitable for dealing with many types of data.
Restrictions on untyped parameters of C++ function templates.
Restrictions on untyped template parameters currently remember that it can be a constant integer (including enumerated types) and pointers to externally connected objects. For historical reasons, floating-point types cannot be used as parameters for untyped templates; pointers and strings are conditional as parameters for untyped templates. I think it has something to do with the scope and life cycle of variables. There will be more trusting introductions later in the book, so we'll take a closer look at it.
What are the above points for attention of C++ function template non-type parameters? have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.