I believe the root cause of your issue is the cyclic dependency of having rooms know about the ship and the ship know about the rooms.
I suggest a different design:
class Ship
{
Room ship_rooms[3][4]; // Note, not dynamically allocated.
public:
void move_unit(Room& from_room, Room& destination)
{
destination.set_unit(from_room.get_unit());
}
void move_unit(unsigned int from_row, unsigned int from_column,
unsigned int dest_row, unsigned int dest_column)
{
ship_rooms[dest_row][dest_column].set_unit(ship_rooms[from_row][from_column].get_unit());
}
Room& get_room(unsigned int row, unsigned int column)
{ return ship_rooms[row][column]; }
};
In the above design, the Ship is in charge of moving units between rooms. Rooms will get (cut) units or set units (receive them). This eliminates the need for a room to know anything about the Ship.
Another possible design is for a room to move something to another room:
class Room
{
Item unit;
public:
void receive_unit(const Room& other)
{
unit = other.unit;
}
void transfer_unit(Room& other)
{
other.unit = unit;
}
};
The above structure allow rooms to communicate with each other, without knowing anything about the ship or container.
Note: These designs resolve the issue of pointer by not requiring pointers. References are used instead.
Downvoters: Please add explanation in the comment.
roomsis not out of bounds?