Default initialization of C++ member array of objects?

Viewed 3378

Suppose I have a C++ class set up as follows:

class Foo{
  public:
    struct Pair{
      int x;
      int y;
      Pair(){ x = 2; y = 4; }
    };

  private:
    Pair pairArr[16];
}

Without otherwise initializing the pairArr, what is the default value of the Pair structs inside it? Does C++ call the constructor (initializing it with x=2, y=4) or are the objects not created yet, leaving me with an array of "junk" objects until I initialize the indices myself?

I know if it is an array of a primitive data type, they are default initialized (if I had an array of ints, they would all be 0). However, I don't know if this behavior holds for more complex objects like my struct here.

1 Answers
Related