本文介绍了如何摆脱波动性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何摆脱波动性?我应该使用哪个c ++风格的转换?
解决方案
使用 const_cast
/ p>
例如,
volatile sample * pvs = new sample ;
sample * ps = const_cast< sample *>(pvs); //抛弃volatile-ness
也就是说, const_cast
用于丢弃常量和易失性。不幸的是,它的名称不包含术语volatile。也许,这是因为关键字 const
在使用中比关键字 volatile
更常见。
How to cast away the volatile-ness? Which c++ style cast should I use?
解决方案
Use const_cast
.
For example,
volatile sample *pvs = new sample();
sample *ps = const_cast<sample*>(pvs); //casting away the volatile-ness
That is, const_cast
is used to cast away both const-ness as well as volatile-ness. Unfortunately, it's name doesn't contain the term "volatile". Maybe, that is because the keyword const
is more common in use than the keyword volatile
.
这篇关于如何摆脱波动性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!