// File: ahack2.cpp // // Another example of a hack. // #include #include using namespace std ; class ABC { public: ABC() { It = 17 ; } // A const member function cannot change // the value of a data member, right? // void ChangeIt() const ; void PrintIt() const { cout << It << endl ; } private: int It ; } ; int main() { ABC X ; cout << "Before calling ChangeIt(): " ; X.PrintIt() ; X.ChangeIt() ; cout << "After calling ChangeIt(): " ; X.PrintIt() ; } void ABC::ChangeIt () const { void *ptr ; stringstream s ; s << &It ; s >> ptr ; * ((int *) ptr) = 42 ; }