How are objects stored in memory in C++?
For a regular class such as
class Object
{
public:
int i1;
int i2;
char i3;
int i4;
private:
};
Using a pointer of Object as an array can be used to access i1 as follows?
((Object*)&myObject)[0] === i1?
Other questions on SO seem to suggest that casting a struct to a pointer will point to the first member for POD-types. How is this different for classes with constructors if at all? Also in what way is it different for non-POD types?
Edit:
In memory therefore would the above class be laid out like the following?
[i1 - 4bytes][i2 - 4bytes][i3 - 1byte][padding - 3bytes][i4 - 4bytes]