Four type conversion operators in C++

Implicit type conversion is safe, but explicit type conversion is risky. The reason why C language adds the syntax of forced type conversion is to emphasize the risks and make programmers aware of what they are doing. However, this way of emphasizing risks is still relatively extensive and granular. It does not indicate what risks exist or what their degree is.

Furthermore, C-style forced type conversion is used uniformly ( )and ( )can be seen everywhere in the code, so it is not conducive to positioning using text retrieval tools (such as Ctrl+F under Windows, grep command under Linux, Command+F under Mac) Key code. In order to make potential risks more detailed, make problem tracing more convenient, and make the writing format more standardized, C++ classifies type conversion and adds four new keywords to support it. They are:

The syntax format of these four keywords is the same, specifically:

xxx_cast<newType>(data)

newType is the new type to be converted to, data is the data being converted. For example, old

Guess you like

Origin blog.csdn.net/shiwei0813/article/details/133102861