What is the purpose of a volatile
member function in C++?
To answer the question about what it means to have a 'volatile member function' (which may or may not be what was originally intended by the person who posted the question), marking a member function as const
or volatile
(or a combined const volatile
) applies those qualifiers to the this
pointer used in the function. As stated by the standard (9.2.1 "The this
pointer"):
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*
.
So by marking the member function as volatile
you'd be making any access to the non-static data members of the object within that member function as volatile
.