1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| /* Let's illustrate how volatile works on user-defined types on an example. */
class Gadget
{
public:
void Foo() volatile;
void Bar();
...
private:
String name_;
int state_;
};
...
Gadget regularGadget;
volatile Gadget volatileGadget;
/* If you think volatile is not that useful with objects, prepare for some surprise. */
volatileGadget.Foo(); // ok, volatile fun called for volatile object
regularGadget.Foo(); // ok, volatile fun called for non-volatile object
volatileGadget.Bar(); // error! Non-volatile function called for volatile object! |
Partager