What does it mean when a member function is volatile?

c++

Solution

The `volatile` qualifier on a member function is analogous to the `const` qualifier. It allows the member function to be called on `volatile` objects:

struct A {
    void f() volatile {}
    void g() {}
};

int main() {
    A volatile a;
    a.f(); // Allowed
    a.g(); // Doesn't compile
}

Problem

I normally see the `const` specifier used to indicate a const member function. But what does it mean when the `volatile` keyword is used? ``` void f() volatile {} ``` This compiles fine for me but I don't understand what this is for. I couldn't find any information about this in my search so any help is appreciated. Update: To make it clear, I know what `volatile` is for. I just don't know what it means in this context.

Original source

Related problems