Generally, casting refers to an explicit conversion, whether it's done by C-style cast (T(v)
or (T)v
) or C++-style cast (static_cast
, const_cast
, dynamic_cast
, or reinterpret_cast
). Conversion is generally a more generic term used for any time a variable is converted to another:
std::string s = "foo"; // Conversion from char[] to char* to std::string
int i = 4.3; // Conversion from float to int
float *f = reinterpret_cast<float*>(&i); // (illegal) conversion from int* to float*
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…