What does a const cast do differently?

前端 未结 6 1518
心在旅途
心在旅途 2020-12-21 06:40

Is there an actual difference between a const_cast and c style cast (ObjectType) ?

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-21 06:57

    C-style cast in C++ attempts a static cast, a reinterpret cast, a const cast, or a combination of those.

    It is recommended to avoid C casts mainly because...

    • reinterpret casts and const casts are used seldomly enough that it's good to emphasize what you're doing,
    • in other cases, when you want a static cast, writing it explicitly gives you additional compile-time checks compared to C casts.

提交回复
热议问题