I feel that during the interview, I am always asked about the conversion type. So before the big interview, I will review it. In fact, I have not made any distinction before, because in reality, especially when I compile a smallProgram, I am not always using it.
The following are four Conversion Mechanisms of C ++:
View plaincopy to clipboardprint?
- Const_cast <t> (expression)
- Dynamic_cast <t> (expression)
- Reinterpret_cast <t> (expression)
- Static_cast <t> (expression)
- Const_cast is usually usedDivision of constant Properties. It is also the only C ++-style transformation operator with this function. It means converting a const to non-Const.
- Dynamic_cast is mainly used to perform "Security downward transformation", that is, to determine whether an object belongsInheritance System. It is the only action that cannot be executed by the old syntax and the only transformation action that may consume significant operation costs.
- Reinterpret_cast intends to perform a low-level transformation. The actual action may depend on the compiler, which means it cannot be transplanted.
- Static_cast is used to forceImplicit conversionFor example, a non-const object is designed for a const object, or an int is converted to a double object. It can also be used to perform reverse conversion of the preceding types. For example, the void * pointer is designed for a typed pointer, convert pointer-to-base to pointer-to-derived. However, const cannot be converted into non-const, which can only be achieved by const_cast.
Note: The text is from Objective C ++.
----------------- Create high-qualityArticleFor more information, thank you ---------------
To create high-quality articles, please recommend them .... Thank you. Please pay attention to my subsequent articles, which will be even better.
Sina Weibo: http://weibo.com/baiyang26
The wine ghost official blog: http://www.ibaiyang.org [recommended to use Google Reader subscription]
Pour wine into the official Douban: http://www.douban.com/people/baiyang26/
If you want to repost this blog,Please specify the source
If you have any comments or suggestions on this article,Leave a message