Four new conversions of C ++

Source: Internet
Author: User

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?
    1. Const_cast <t> (expression)
    2. Dynamic_cast <t> (expression)
    3. Reinterpret_cast <t> (expression)
    4. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.