That is, what is the standard a compiler uses to generate a class? For example, let's say that I have class C
with members x
, y
, and z
, and I want to know the offset of z
within that class. Can I just add up the data-type sizes of the other members, like I would for a structure?
No You cannot.
Compilers are free to align the members as they chose to.It is an implementation detail of the compilers.
If you're working with a POD, then you can use the offsetof macro.
But If working with a Non-POD, then I suppose there won't be any portable method to do so.