Type conversion in C ++

Source: Internet
Author: User
The types in C ++ include four types: static_cast, dynamic_cast, const_cast, and reinterpret_cast. Four types of reinterpret_cast: Forced type conversion operator, modifying the operand type, giving the object's BIT model without binary conversion; Use with caution; static_const: the conversion between the parent class and the Child class between classes. It is safe to convert the pointer or reference of the parent class to the base class. In turn, it is not safe. Conversion between basic data. Compared with reinterpret_const, static_const can be converted to binary values. It is basically the same as the C-style () Conversion Function. const_cast: const is converted to non-Const. dynamic_const: conversion between parent classes and child classes between classes ,When the class hierarchy performs upstream conversion, the effect is the same as that of static_const. Dynamic_const performs a dynamic check. The base class must contain virtual functions, but static_const does not. Both dynamic_const and static_const fail during the downstream conversion, but dynamic returns NULL, while static_const is incorrect at the Compilation Time, which fully indicates a dynamic moment check and a compilation time error.

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.