const_cast vs static_cast

后端 未结 4 1034
半阙折子戏
半阙折子戏 2020-12-16 17:41

To add const to a non-const object, which is the prefered method? const_cast or static_cast. In a recent question, s

4条回答
  •  孤街浪徒
    2020-12-16 18:25

    I'd say static_cast is preferable since it will only allow you to cast from non-const to const (which is safe), and not in the other direction (which is not necessarily safe).

提交回复
热议问题