Я постараюсь сделать мою задачу максимально лаконичной:
У меня есть 3 класса, класс роботов, класс Point и мировой класс.
class Point
{
private:
int x;
int y;
public:
void set(int x, int y)
{
this->x = x;
this->y = y;
}
int getX()
{
return x;
}
int getY()
{
return y;
}
};
class Robot{
private:
Point roboLocale;
public:
Robot()
{
}
void init()
{
roboLocale.set(0, 0);
}
class World
{
private:
char arr[10][10];
public:
World()
{
std::fill(arr[0], arr[0] + 10 * 10, ' ');
}
void injectRobot()
{
arr[roboLocale.getX()][roboLocale.getY()] = '@'; // would like to access robotLocales x and y coords
}
void displayField()
{
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
std::cout << "[" << arr[i][j] << "]";
}
std::cout << std::endl;
}
}
};
int main()
{
World field;
Robot robot;
robot.init();
field.injectRobot();
field.displayField();
}
Inмой класс World под void injectRobot()
Я пытаюсь получить доступ к функциям robotLocale
getX () и getY (), чтобы «внедрить» робота в мой World::arr
.Я просто не могу понять, как это сделать, или вообще возможно ли это.Любая помощь будет принята с благодарностью.