I asked this function based on this concept (maybe incorrect?!): Wherever a const can exist, a volatile can exist at the place.
class classA
{
public:
const int Foo() const;
}
Here the first "const" means the return value is const, we can not change it. the second const means "Is Query", this function can not change the member variable and can not call non-const function.
Now comes to volatile: I can understand what volatile does on a variable, like "volatile int a;" However I have no idea of the difference among the following:
Case 1: The return type is volatile?
volatile void Function1();
Case 2: The function can only call volatile functions? Why add volatile here? Any example?
void Function2() volatile;
Case 3: Is it valid? If yes, is it simply a combination of Case 1 and Case 2?
volatile void Function3() volatile;
When we put the const at the end of function declaration, it has a beautiful name: "Is Query" Can you give a decent name/alias to the "volatile" in Case 2? I mean, whenever we call this name, we can know we are talking about Case 2, not case 1.
Thank you in advance!