Let's say I create 5 objects, all from the same class. Would the byte offset of t开发者_高级运维he first object be 0? How would I find out the byte offset of the other objects?
"Byte offset" from what? Are you creating an array of 5 such objects? In that case, sure, the byte offset of the first one (from the start of the array) is 0; as for other objects,
static_cast<char*>(&thearray[i]) - static_cast<char*>(&thearray[0])
is the byte offset of the i
th one.
Regardless of what you mean by offset
, you can always examine the address of the objects yourself:
printf("%p %p", (void *) &thingOne, (void *) &thingTwo);
精彩评论