const cast有什么不同? [英] What does a const cast do differently?

查看:45
本文介绍了const cast有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

const_cast和c样式转换(ObjectType)之间是否存在实际差异?

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

推荐答案

A const_cast 传达有关C强制转换无法实现的强制转换背后意图的具体信息。

A const_cast conveys specific information about the intent behind the cast that a C cast cannot.

如果您不小心尝试使用 const_cast 用于添加或删除 const volatile 以外的目的,编译器将

If you accidentally try to use a const_cast for purposes other than adding or removing const or volatile, the compiler will help you with an error message.

此外, const_cast 也是可搜索的,与C样式的强制转换不同。

Also, const_cast is searchable, unlike a C-style cast.

这篇关于const cast有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆