C + + type conversion operators

Source: Internet
Author: User

C + + provides 4 type-to operators, namely: Static_cast, dynamic_cast, reinterpret_cast, and const_cast;

The syntax format is as follows:

Type conversion Operators < type_id> (expreession);

Description: TYPE_ID is the target type; expression is the original data.

1. dynamic_cast: It is mainly used for upstream conversion and downlink conversion between class hierarchies. The dynamic_cast and static_cast effects are the same when you move up and down the class hierarchy: When you run a downstream conversion, dynamic_cast has type checking, which is more secure than static_cast (dynamic_ The cast operator also requires the support of the virtual mechanism).

2, reinterpret_cast: You can convert the value of shaping to an address. The C + + compiler believes that programmers are well aware of the consequences of such coercion, and therefore it is reasonable to take the unpredictable consequences that it brings to the programmer.

3. The Const_cast:const_cast conversion is a const or volatile qualifier used to remove a variable.

C + + type conversion operators

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.