c++中static_cast用法

static_cast是指显性类型强制转换,如:

 结果为a= 120. 和C语言学习时的显性意义一样,但是编译器会对此类型转换进行检查。
另外还有另外3种转换:

  1. const属性用const_cast。
  2. 基本类型转换用static_cast。
  3. 多态类之间的类型转换用daynamic_cast。
  4. 不同类型的指针类型转换用reinterpreter_cast。
posted @ 2023-06-28 14:09  手磨咖啡  阅读(150)  评论(0)    收藏  举报