One more thing. I had to add a virtual destructor to A to get this to work:
class A {
public: int a; virtual ~A(){}
};
// ....
A *d2 = (A*)d;
cout << boolalpha << (typeid(*d2) == typeid(D)) << endl;
C *d3 = (C*)d;
cout << boolalpha << (typeid(*d3) == typeid(D)) << endl;
Output is now:
true
false
Without virtual destructor:
false
false
So you can't rely on serialization working properly using only
TypeInfo/offsets
