Transfer from Baidu Encyclopedia:
用法:static_cast < type-id > ( expression )
The operator expression to convert type-id type, but without run-time type checking to ensure the safety of the conversion
. It mainly has the following several uses:
① for the
class hierarchy for
the base class (parent class) and
a derived class
pointers between (subclass) or reference conversion.
Converting an uplink (derived class pointer or reference into a base class shown) are safe;
When downstream converter (pointer or reference to the base class to the derived class represented converted), because there is no dynamic type checking, it is unsafe.
② for switching between the basic data types, such as int converted into char, to convert int enum. Security developers such conversion should be guaranteed.
③ convert null pointer into the target type null pointer.
④ to convert any type of expression into a void type.
Note: static_cast can not convert out expression of const, volatile, or __unaligned property.
In C ++ static_cast and
reinterpret_cast
difference
C ++ primer
Chapter fourth edition to write a
compiler
implicitly perform any
type of conversion
can be done by a display static_cast; reinterpret_cast generally provide a lower layer bit operand mode reinterpreted