c++ memory in array of class objects

Viewed 1464

I have a class like this:

class Object {
public: 
    unsigned char data[8];
    // other variables
    // functions etc...
 };

The question is - are the object members all stored in the same place in memory relative to the object? So if I have an array: Object array[3], given a char pointer char* data_ptr = array[0].data, will data_ptr + (sizeof(Object)) then always point to array[1].data?

(I've read a couple of Q/As about how there might be padding inbetween data members of classes and structs - but I don't think they answer my question.)

Thanks in advance, Ben

5 Answers
Related