C++中volatile
成员函数的作用是什么?
最佳答案
要回答有关“ volatile 成员函数”意味着什么的问题(可能是也可能不是发布问题的人最初的意图),将成员函数标记为 const
或 volatile
(或组合的 const volatile
)将这些限定符应用于函数中使用的 this
指针。如标准所述(9.2.1“this
指针”):
The type of this in a member function of a
class X
isX*
. If the member function is declaredconst
, the type of this isconst X*
, if the member function is declaredvolatile
, the type ofthis
isvolatile X*
, and if the member function is declaredconst volatile
, the type of this isconst volatile X*
.
因此,通过将成员函数标记为 volatile
,您将对该成员函数内的对象的非静态数据成员进行任何访问作为 volatile
。
关于c++ - C++中 volatile 成员函数的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2444734/