c++ figuring out memory layout of members programatically
<p>Suppose in one program, I'm given:</p>

<pre><code>class Foo {
  int x;
  double y;
  char z;
};

class Bar {
  Foo f1;
  int t;
  Foo f2;
};

int main() {
  Bar b;
  bar.f1.z = 'h';
  bar.f2.z = 'w';
  ... some crap setting value of b;
  FILE *f = fopen("dump", "wb"); // c-style file
  fwrite(&amp;b, sizeof(Bar), 1, f);
}
</code></pre>

<p>Suppose in another program, I have:</p>

<pre><code>int main() {
  File *f = fopen("dump", "rb");
  std::string Foo = "int x; double y; char z;";
  std::string Bar = "Foo f1; int t; Foo f2;";

  // now, given this is it possible to read out
  // the value of bar.f1.z and bar.f2.z set earlier?
}
</code></pre>

<p>WHat I'm asking is:
  given I have the types of a class, can I figure out how C++ lays it out?</p>
