Volatile Member Functions. McGraw-Hill The Complete Reference Fourth Edition
Διαφήμιση
Διαφήμιση
C h a p t e r 2 3 : N a m e s p a c e s , C o n v e r s i o n F u n c t i o n s , a n d O t h e r A d v a n c e d T o p i c s
609 mutable int i; int j; public: int geti() const { return i; // ok
} void seti(int x) const { i = x; // now, OK.
}
/* The following function won't compile.
void setj(int x) const { j = x; // Still Wrong!
*/
}
}; int main()
{
Demo ob; ob.seti(1900); cout << ob.geti();
} return 0;
Here, i is specified as mutable, so it may be changed by the seti( ) function. However,
j
is not mutable and setj( ) is unable to modify its value.
Volatile Member Functions
Class member functions may be declared as volatile, which causes this to be treated as a volatile pointer. To specify a member function as volatile, use the form shown in the following example: class X { public:
}; void f2(int a) volatile; // volatile member function
Λήψη
Διαφήμιση