class MyClass { int x, y; void foo() volatile { // do stuff with x // do stuff with y } };
Do I need to declare
You don't have to declare the member variables explicitly..
From Standard docs 9.3.2.3,
Similarly, volatile semantics (7.1.6.1) apply in volatile member functions when accessing the object and its nonstatic data members.