/* A Poem in C++ by Chuck Liang */ /* AKA: What Mother Never Told You About C++ Part I: Pointers and Privacy */ using namespace std; #include class bigobject { private: int x; double y; public: bigobject() { x = 2; y = 3.14; //cout << "wherefore art thou, my double: " // << ((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+4); cout << "The \"private\" integer is " << *x << endl; cout << "and the not-so-private double was " << *y << endl; *y += 5.86; cout << "but what I get back now reads " << A->gety() << endl; cout << "Private? Says who?\n"; return 0; } // To purchase the entire "What Mother Never Told You" series on DVD, visit // www.motherwisdom.com