I'm working on a C++ project which basically uses a couple of classes to simulate a retail environment; so far everything has gone smoothly, but I haven't been using C++ for very long and I'm a little stumped on how this array is supposed to work.
//Customer.h
private:
std::array< CustomerOrder *, 3 > orderList;
Basically, the array is declared in the Customer.h file as private, but the Customer.h and Customer.cpp files also provide a method
addOrder(CustomerOrder *c)
for adding CustomerOrder pointers(CustomerOrder being another class) to the array. From my experience, the logic for the method is pretty straightforward: Use a for loop to find the first index containing a null pointer, then insert a pointer into that index.
The issue is, that involves first initializing the array to null pointers, and I'm not sure how or in which file I should do this. Since the array is private, I would assume I have to initialize it in the .h file using something along the lines of
for(size_t i = 0; i < orderList.size(); ++i)
orderlist[i] = nullptr;
or
orderlist[3] = {nullptr}
Can I/Do I have to do this in a .h file? And is there a more trustable way to initialize the array?
For reference, I'm using the C++11 standard, if that makes any difference.