#include #include "family.h" using namespace std; inline void add(const void *& p, ptrdiff_t diff) { p = static_cast(p) + diff; } template const T& field(const void *& p, const char *s = "") { const T& t = *reinterpret_cast(p); cout << p << ": " << t << " (" << s << ")\n"; add(p, sizeof t); return t; } void print(const mother *m) { const void *p = m; cout << "\nThis mother starts at address " << p << ".\n"; const void *pd = field(p, "pointer to table"); const ptrdiff_t diff = field(pd, "offset"); field(p, "mother::j"); cout << p << " is the address of the first byte after the mother.\n" << "The mother's grandparent starts at address " << p; if (diff < 1000) { cout << " + " << diff << " == "; add(p, diff); cout << p; } cout << ".\n"; field(p, "grandparent::i"); }