C++ four new transformation functions

  1. C-style transformational action
(T)expression //将expression转型为T
  1. Functional style transition action
T(expression) //将expression转型为T
  1. Four new transformations of C++
const_cast<T>(expression)
dynamic_cast<T>(expression)
reinterpret_cast<T>(expression)
static_cast<T>(expression)
  • const_cast: It is the only cast operator that can be used to convert the constant of an object.
  • dynamic_cast: Mainly used to perform "safe down-casting", that is, to determine whether an object belongs to a certain type in the inheritance system (convert pointer-to-derived to pointer-to-base). The only action that cannot be performed with the old-style grammar is the only transformational action that may cost significant operating costs.
  • reinterpret_cast: The purpose is to perform low-level conversion (such as converting pointer-to-int to int). The actual actions and results may depend on the compiler, which means that it is not portable.
  • static_cast: Used to force implicit conversions, and can also be used to perform reverse conversions of the above-mentioned multiple conversions.

Guess you like

Origin blog.csdn.net/gaggagaasd/article/details/108895670