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

What are the new features of Central11?

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

Share

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

The main content of this article is to explain "what are the new features of Category 11". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the new features of Category 11?"

What is Clear11?

Category 11, once known as C++ Technical Report 0x, is an extension and revision of the current C++ language. It not only contains new functions of the core language, but also extends C++ 's standard program library (TR1) and incorporates most C++ API 1 (TR1) libraries (except for special functions in mathematics).

Clocking 11 includes a number of new features, including lambda expressions, type derivation keywords auto, decltype, and numerous improvements to templates.

New keyword

Auto

The function of auto*** is introduced in Category 11 to automatically derive the type.

Automatic type derivation of auto, which is used to infer the data type of a variable from an initialization expression. Through the automatic type derivation of auto, our programming work can be greatly simplified.

Auto actually deduces the types of variables at compile time, so it will not adversely affect the running efficiency of the program.

In addition, it seems that auto does not affect compilation speed, because compilation time is supposed to deduce on the right and then determine whether it matches the left.

Auto a; / / error. Auto performs type derivation through initialization expressions. If there is no initialization expression, you cannot determine the type of a: auto I = 1; auto d = 1.0; auto str = "Hello World"; auto ch = 'A'; auto func = less (); vector iv; auto ite = iv.begin (); auto p = new foo () / / A pair of custom types for type derivation

Auto not only has the above applications, but also shows its skill in templates. For example, in the following example of a processed product, you must declare the template parameter Product if you do not use auto:

Template void processProduct (const Creator& creator) {Product* val = creator.makeObject (); / / do somthing with val}.

If you use auto, you can write:

Template void processProduct (const Creator& creator) {auto val = creator.makeObject (); / / do somthing with val}

Get rid of the troublesome template parameters, and the whole code becomes more correct.

Decltype

Decltype is actually a bit like the inverse function of auto. Auto allows you to declare a variable, while decltype can get a type from a variable or expression. Examples are as follows:

Int x = 3; decltype (x) y = x

Some people may ask, what is the usefulness of decltype? let's continue with the above example, what if we want to use the product as a return value in the example of a processed product above? We can write like this:

Template auto processProduct (const Creator& creator)-> decltype (creator.makeObject ()) {auto val = creator.makeObject (); / / do somthing with val}

Nullptr

Nullptr is a new type introduced to solve the ambiguity problem of NULL in C++, because NULL actually stands for 0.

Void F (int a) {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