struct MyStruct
{
int a;
int b;
};
struct AnotherStruct
{
MyStruct mySubData;
char string[8];
};
class MyClass
{
private:
AnotherStruct myData;
public:
MyClass() {} // implicit default ctor for myData
//MyClass() : myData() {} // explicit default ctor for myData
};
The explicit default ctor for myData would initialize all the primitive member values to zero as far as I know.
But what about the implicitely called default ctor? I can't read this out of the standard.
AnotherStruct's default constructor, since it is not defined, will call the default constructor for
MyStruct and for 8 chars. The default constructor for all POD types does nothing. It does not initialize them to zero.
You'll want
1 2 3 4 5
struct MyStruct {
MyStruct() : a(), b() {}
int a;
int b;
};