Does the positioning of the ‘volatile’ keyword in a method declaration affect its functionality?
i.e., is there any difference between the following two pieces of code?
A.
class Test
{
public:
volatile void testMe()
{
}
};
B.
class Test
{
public:
void testMe() volatile
{
}
};
And same goes when the member function has a return value. Thank you!
It is the same as for the
constqualifier.In the first example, the
volatileapplies to the return value of the function. It is void in this case, so it doesn’t make much sense. In fact, it doesn’t make much sense to return by volatile value*. A volatile return type would only make sense for a reference:In the second case, it means that the method is
volatile, hence it can be called on (non-const) non-volatile and volatile instances of classTest. A similar method without thevolatilequalifier could not be called on avolatileinstance.*Unless that value is a pointer