0

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)
{

}

1 Answer 1

2

Use value initialization:

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

or

y::y()
: arrayList{}
{
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.