Volatile member functions and constant member functions in volatile
Many people say
They are very similar in the sense that the pointer is marked const / volatile. It can only access member functions marked const / volatile
But actually defining a member function as const has an additional impact, which makes the function read-only Any modification of an object inside a function will result in a compiler error Is there such an analogy in volatile member functions?
Solution
Well, a volatile member function makes the object member volatile, that is, it's like it's defined as volatile t * const Therefore, any reference to a member variable is also unstable
Remember that volatile read / write is an operation that the compiler cannot omit / reorder They are usually used to implement memory mapped hardware devices or the like
Frankly, I've never used this feature, except to do some clever tricks to filter access to functions instead of taking advantage of object volatility If your code is low enough to require volatile, you may want to put volatile in the variables you need