#include using namespace std; class readonlyint { private: int x; public: readonlyint(int x0) {x=x0;} // constructor int getx() { return x; } // allows read access (accessor) }; //Show how to change the private int variable inside an instance of this class in main: int main() { readonlyint* const R = new readonlyint(1); //const means pointer can't change readonlyint T(1); //... do something to change the private int in R to 2 *((int*)R) = 2; *((int*)&T) = 2; cout << R->getx() << endl; // should print 2. cout << T.getx() << endl; // should print 2. return 0; }