vendredi 14 octobre 2022

Initializing an array of objects created on the heap

Given the non trivial data structure:

claas MyClass
{
public:
  MyClass():x(0), p(nullptr)
  {}

private:
  int x;
  int* p;
};

Is there any guarantee provided by the c++ specification that the default constructor will be called for each instance of MyClass in the array pointed by the ptr?

    int main()
    {
      MyClass* ptr = new MyClass[5];
    }

Aucun commentaire:

Enregistrer un commentaire