With static_cast<>()
other C ++ type conversion, do not use int y = (int) x; or int int Y = (X); .
Definitions: C ++ is different from the introduction of different types of C type conversion operation.
Advantages: C language type conversion operation that vague: sometimes do cast (e.g., (int) 3.5 of ), the type of conversion is sometimes done (e.g., (int) "Hello" ). In addition, C ++ casts to find easier and more eye-catching.
Disadvantages: syntax is disgusting.
Conclusion: The use of C ++ rather than C-style style type conversion.
-
static_cast
: C-style conversion and similar cast do value, or a pointer to a parent class clear upconverting subclass; -
const_cast
: Removeconst
property; -
reinterpret_cast
: Between pointer and integer types or other unsafe pointer interchangeable, when do you use for everything clear in mind only; -
dynamic_cast
: Do not use addition to the test, in addition to unit testing, if you need to type information determined at runtime, illustrate the design is flawed.