/* What Mother Never Told You About C++ A Poem in C++ by Chuck Liang */ using namespace std; #include class bigobject { private: int x; double y; public: bigobject() { x = 2; y = 3.14; //cout << "location of y relative to this: " // << ((char*)this) - ((char*)&y) << endl; } double gety() { return y; } }; int main(int argc, char **argv) { bigobject *A = new bigobject(); int *x = (int*)A; double *y = (double*)((char*)A+8); cout << "The \"private\" integer is " << *x << endl; cout << "and the private double was " << *y << endl; *y += 1.86; cout << "but somehow it became " << A->gety() << endl; cout << "Private? Says who?\n"; return 0; }