C++: Type Conversion

const_cast: Eliminates the constant attribute of a variable, and can be modified after assigning a constant to a variable, which can eliminate constant pointers and constant references.

 

static_cast: Explicit type conversion, which can be used instead of mandatory type conversion in C language, but does not perform type safety checking, and supports all meaningful type conversions.

 

reinterpret_cast: Redefine type conversion, which can convert two unrelated types between types, but it is usually not recommended, and some compilers may not support it. The usual way is to convert other types to void*, or to convert other types to void*. void* is converted to another type. No type checking is done at runtime.

 

dynamic_cast: supports type conversion of class inheritance, can convert pointers or reference conversions with class inheritance structure, supports runtime type detection, only supports up-casting after testing, and does not support down-casting.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325563113&siteId=291194637