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 = b
has the same address asb
, i.e.static_cast<A*>(b) == reinterpret_cast<A*>(b)
. -
B bs[n]
is an array ofB
objects.&bs[i] == static_cast<B*>(static_cast<void*>(bs) + i * sizeof(B))
. -
offsetof
can be used to access data members ofA
and ofB
, fromb
:int i = *static_cast<int*>(static_cast<void*>(b) + offsetof(B, m_i))
.
Aucun commentaire:
Enregistrer un commentaire