Type conversions in C + + types conversion

Source: Internet
Author: User

# # #Implicit Conversions Implicit conversion
* can be freely converted between the basic types;
* Can convert any type of pointer to void pointer;
* Sub-class pointer can be converted to base class pointer;
* Will produce warning

# # #static_cast静态转换
* Similar to implicit cast
* can be freely converted between sub-class base class pointer
* No run-time check

# # #dynamic_cast动态转换
* Generally used for polymorphism
* will check if pointer points to valid object

# # #reinterpret_cast
* Can be converted between any type of pointer
* No check, very dangerous

# # #const_cast
* can be converted between const and non const pointer

# # #C Style cast
(type) val or type (val), converted in the following order of precedence:

* Const_cast
* STATIC_CAST (though ignoring access restrictions
* STATIC_CAST (see above) and then const_cast
* Reinterpret_cast
* Reinterpret_cast, then const_cast

Type conversions in C + + types conversion

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.