implicit POD ctor

Hello!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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.

Thanks for your help!
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;
};


etc. Also for AnotherStruct.
Topic archived. No new replies allowed.