I am aware you cannot use an initialiser list for an array. However I have heard of ways that you can set an array of pointers to NULL in a way that is similar to an initialiser list.
I am not certain how this is done. I have heard that a pointer is set to NULL by default, though I do not know if this is guaranteed/ in the C++ standard. I am also not sure if initialising through the new operator compared to normal allocation can make a difference too.
Edit: I mean to do this in a header file/constructor initialisation list. I do not want to put it in the constructor, and I do not want to use a Vector.
In order to set an array of pointers to nulls in constructor initializer list, you can use the
()initializerUnfortunately, in the current version of the language the
()initializer is the only initializer that you can use with an array member in the constructor initializer list. But apparently this is what you need in your case.The
()has the same effect on arrays allocated withnew[]In other contexts you can use the
{}aggregate initializer to achieve the same effectNote that there’s absolutely no need to squeeze a
0or aNULLbetween the{}. The empty pair of{}will do just fine.