c++ - C++中 volatile 成员函数的目的是什么?

标签 c++ volatile

C++中volatile成员函数的作用是什么?

最佳答案

要回答有关“ volatile 成员函数”意味着什么的问题(可能是也可能不是发布问题的人最初的意图),将成员函数标记为 constvolatile(或组合的 const volatile)将这些限定符应用于函数中使用的 this 指针。如标准所述(9.2.1“this 指针”):

The type of this in a member function of a class X is X*. If the member function is declared const, the type of this is const X*, if the member function is declared volatile, the type of this is volatile X*, and if the member function is declared const volatile, the type of this is const volatile X*.

因此,通过将成员函数标记为 volatile,您将对该成员函数内的对象的非静态数据成员进行任何访问作为 volatile

关于c++ - C++中 volatile 成员函数的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2444734/

相关文章:

c++ - 访问图像像素; MatIterator_<> 和 Mat::at 运算符的比较

c++ - 如何选择像魔杖一样的区域并使用 OpenCV 对其进行洪水填充?

由于删除局部变量,Java volatile 关键字行为发生变化

java - volatile 关键字有什么用?

java - 在java中同时访问 volatile 变量

c - cast 中的中间指针必须是 "const qualified"- 为什么?

c++ - 无法在程序中指定文件路径前缀

c++ - 静态变量释放顺序

c++ - C语言有前置自增和后置自增的历史原因是什么?

volatile 变量的更改仅在单步执行代码或关闭优化时发生