How can my "Player" class access a function of my "Map" class?
The place I want it in is commented.
Thanks.
#include <iostream>
#include <string>
using namespace std;
class Map
{
public:
Map();
~Map();
void Map::print();
int Map::sendroom(int x_coord, int y_coord);
private:
int i;
int p;
int w;
static const int MAP_HEIGHT = 9;
static const int MAP_WIDTH = 9;
int room_numbers[MAP_WIDTH][MAP_HEIGHT];
static const int TOTAL_ROOMS = MAP_HEIGHT*MAP_WIDTH;
string room_titles[0];
string room_description[0];
};
Map::Map()
{
room_numbers[MAP_HEIGHT][MAP_WIDTH];
room_titles[TOTAL_ROOMS];
room_description[TOTAL_ROOMS];
w = 0;
for (i=0; i < MAP_HEIGHT; i++)
{
for (p=0; p < MAP_WIDTH; p++)
{
room_numbers[i][p] = w;
w++;
}
}
}
Map::~Map()
{
}
void Map::print()
{
for (int a=0; a<MAP_HEIGHT; a++)
{
for (int b=0; b<MAP_WIDTH; b++)
{
cout << room_numbers[a][b]<< " ";
}
cout << "\n";
}
}
int Map::sendroom(int x_coord, int y_coord)
{
cout << room_numbers[x_coord][y_coord];
}
class Player
{
public:
Player();
~Player();
void Player::gonorth();
private:
int room_numberx;
int room_numbery;
int new_room;
};
Player::Player()
{
room_numberx = 0;
room_numbery = 0;
}
Player::~Player()
{
}
void Player::gonorth()
{
room_numberx++;
new_room = //Map.sendroom function goes here but I can't access it
cout << "New room number: " << new_room << "\n";
}
int main()
{
Map map;
Player player;
player.gonorth();
cin.get();
}