I wonder if volatile can be used anywhere const can, and what each case would mean.
volatile dummy_class
volatile dummy_class&
dummy_class volatile*
dummy_class *volatile
dummy_class volatile *volatile
These are all distinct cases when const is involved, do the same semantics apply for volatile?
This is section 3.9.3 CV-qualifiers from C++11 draft n3290:
So
constandvolatilecan be used in the same spots, possibly in conjuction.Paragraph 3 of that section notes a slight difference in how they apply to class objects:
but that’s pretty logical.
volatile-qualified objects have stricter requirements for the as-if rule, namely:The volatility gets attached to the object in the same way
constdoes:For non-static member functions (§9.3.1):
So volatility like const-ness applies to the type of
thisinside the function.Neither
constnorvolatilecan be applied to static member functions.