For which categories of types (standard layout, POD, trivial type, alignment constraints...) are the following assumptions valid?
B is a subclass of A, and B* b a pointer to a B object.
-
A* a = bhas the same address asb, i.e.static_cast<A*>(b) == reinterpret_cast<A*>(b). -
B bs[n]is an array ofBobjects.&bs[i] == static_cast<B*>(static_cast<void*>(bs) + i * sizeof(B)). -
offsetofcan be used to access data members ofAand ofB, fromb:int i = *static_cast<int*>(static_cast<void*>(b) + offsetof(B, m_i)).
Aucun commentaire:
Enregistrer un commentaire