Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Advanced example Analysis of C++ data structure template

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces "C++ data structure template advanced case analysis" in detail, with detailed contents, clear steps and proper handling of details. I hope this "C++ data structure template advanced case analysis" article can help you solve your doubts. Let's follow the editor's ideas slowly and deeply, together to learn new knowledge.

Untyped template parameter

Template parameter classification type shape participates in non-type parameter.

Type template parameter: the parameter type name that appears in the template parameter list, followed by class or typename.

Non-type template parameter: use a constant as a parameter of the template, which must be a type parameter in the plastic family, otherwise it will not work. It can be used as a constant in the template.

Example:

/ / Type template parameter namespace wxj {/ / untype template parameter N is a constant parameter Can only be plastic family: int short char long custom types and other types cannot be used as cost type template parameters / / the result template class Array {public: Array (): _ size (N) {} must be confirmed at compile time. T & operator [] (size_t I) {return _ ARR [I] } const T & operator [] (size_t I) const {return _ ARR [I];} size_t size () {return _ size } bool empty () {return _ size = = 0;} private: t _ arr [N]; size_t _ size;}; void TestArray () {Array arr For (size_t I = 0; I < arr.size (); + + I) {arr [I] = I;} for (size_t I = 0; I < arr.size (); + + I) {cout

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report