#include using namespace std; class Silly { public: Silly(int & x): xRef(x){} void X(int val) { xRef = val; } int X(void) const { return xRef; } private: int & xRef; }; int main() { int x = 5; int y = 2001; Silly aClass(x); int & xRef = x; cout << " x = " << x << endl; cout << " xRef = " << xRef << endl; cout << " aClass.X() = " << aClass.X() << endl; cout << endl; xRef = -99; cout << " x = " << x << endl; cout << " xRef = " << xRef << endl; cout << " aClass.X() = " << aClass.X() << endl; cout << endl; x = 1001; cout << " x = " << x << endl; cout << " xRef = " << xRef << endl; cout << " aClass.X() = " << aClass.X() << endl; cout << endl; aClass.X(43); cout << " x = " << x << endl; cout << " xRef = " << xRef << endl; cout << " aClass.X() = " << aClass.X() << endl; cout << endl; // notice, this copys the value, it does not change the reference. xRef = y; cout << " x = " << x << endl; cout << " xRef = " << xRef << endl; cout << " aClass.X() = " << aClass.X() << endl; cout << endl; return 0; }