One of the goals of C ++ rules is to ensure that "type errors will never happen ".
Transformation damages the type system.
Old transformation style:
(T) express;
T (Express );
New Transformation:
1,
Const_cast <t> (expression ).
A single object may have more than one address, which is directed by a base class pointer and a subclass pointer.
Because we know how to design objects, the transformation may be possible on a certain platform, but not on other platforms.
Remember:
1,
If possible, try to avoid transformation, especially to avoid dynamic_casts in code that focuses on efficiency. If there is a design that requires transformation, consider an alternative solution that does not require transformation.
2,
If the transformation is necessary, try to hide it behind a function. Then the customer can call the function without putting the transformation into their own code.
3,
We would rather use C ++-style (New Transformation) than old transformation. The former is easy to identify and has a different role. That is, the new transformation target is very narrow.