You can see the memory layout as two sub-structs foo
and bar
gathered in one named bar
.
Your bar class will look like that in memory:
*******
foo members:
-char* item (sizeof(char*)
*******
bar members:
*******
When you will create a new bar
, you will reserve memory for these two structures.
In your case this will reserve enough memory for the char* which is probably 4 bytes in case of a x86 compiler.
In a normal usecase, bar
's constructor will contains everything related to bar
's member. bar
's constructor can also call "manually" foo
's constructor within the initialization list or a raw call. Otherwise the compiler will call the foo
's default constructor for you.