How to cast away the volatile-ness?

社会主义新天地 提交于 2019-12-20 09:47:58

问题


How to cast away the volatile-ness? Which c++ style cast should I use?


回答1:


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, its name doesn't contain the term "volatile". Maybe, that is because the keyword const is more common in use than the keyword volatile. As one of the comment says, cv_cast would have been more appropriate name!



来源:https://stackoverflow.com/questions/5249895/how-to-cast-away-the-volatile-ness

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!