user3348712
user3348712

Reputation: 161

how to properly instantiate an array of pointers in constructor in c++?

Simple question about instantiating an array through a constructor. I have an array of pointers to class x, I'm trying to set the array members to nullptr through the constructor.

This is my y.h

#include <array>
#include "x.h"

class y
{
public:

static const size_t number = 20;
y();


private:
std::array<x*, number> arrayList;
};

this is my y.cpp

#include "y.h"
#include "x.h"
#include <array>

using namespace std;

y::y()
: arrayList(nullptr)
{

}

Upvotes: 0

Views: 58

Answers (1)

juanchopanza
juanchopanza

Reputation: 227608

Use value initialization:

y::y()
: arrayList()
{
}

or

y::y()
: arrayList{}
{
}

Upvotes: 2

Related Questions