Is there any difference between type casting & type conversion?

前端 未结 4 918
一整个雨季
一整个雨季 2020-12-11 04:54

Is there any difference between type casting & type conversion in c++.

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-11 05:23

    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(&i); // (illegal) conversion from int* to float*
    

提交回复
热议问题