I don't know how you found this code, however, I wouldn't recommend using it unless you have to.
Let's break it down, if you would be writing: Room name[3]
, it would mean an array to 3 Rooms. It has been extended to Room* name[3]
to become an array to 3 pointers to Room. And following that, it has been given reference semantics Room* &name[3]
. Unfortunately, this doesn't compile, as it gets interpret to an array of to 3 references to points of Room, hence the parenthesis, which make this:
Room *(& name)[3]
My recommendation would be to use C++ structures instead of the C ones, by using the standard library <array>
.
void initList_v(std::array<Room *, 3> &roomsList_p)
{
roomsList_p[3] = new Room[3];
}
As it's bad practice to have raw pointers with ownership, this even could become updated:
void initList_v(std::array<std::unique_ptr<Room[]>, 3> &roomsList_p)
{
roomsList_p[3] = std::make_unique<Room[]>(3);
}
And as returning by output arguments is also bad practice, it makes more sense to actually return.
auto initList_v()
{
std::array<std::unique_ptr<Room[]>, 3> roomsList_p;
roomsList_p[3] = std::make_unique<Room[]>(3);
return roomsList_p;
}
Some final advice: You code contains a bug, as you are indexing out-of-bounds.