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 kinds of ​ C++ cv-qualifier

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces "what kinds of C++ cv-qualifier there are". In daily operation, I believe many people have doubts about what kinds of problems C++ cv-qualifier has. Xiaobian consulted all kinds of information and sorted out simple and easy operation methods. I hope to help you answer the doubts of "what kinds of C++ cv-qualifier there are"! Next, please follow the small series to learn together!

C++ cv-qualifier

There are three types of CV-qualifiers: const and volatile, mutable.

const/volatile is called type qualifiers.

They can be combined with any T into three different types:

const modified T, usually const T or T const

volatile modified T

const-volatile modified T

Note that const/volatile is a direct modifier of type.

int volatile a, b; indicates that both types of a,b are volatile int. And int a, volatile b; is illegal.

That is, const and volatile must modify type directly, and cannot modify variables.

This is quite different from pointer declarations *, reference declarations &, array declarations [], etc.

For example int a, *b, c[10], &d = a; are legal.

const and volatile can both modify a type to indicate that "whenever this variable is read, read from the original memory address", preventing it from being optimized by the compiler.

mutable modifies (1)non-static (2)class members of (3)non-reference (4)non-const (5)type. Notice that there are five conditions in this sentence.

class X {

mutable const int* p;

OK. as (mutable int) (const*) p;

P is not a const member.

mutable int* const q;

ill-formed. as (int*) (mutable const) q;

Q is a const member.

};

Mutable in C++ is a storage-class-specifier, not a type qualifier, which is probably why it cannot coexist with static. At this point, about "C++ cv-qualifier what kinds of" learning is over, I hope to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

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

Internet Technology

Wechat

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

12
Report