Как передать данные функции в другую функию С++
как передать все данные объектов из функции setup в функцию graphic, чтоб небыло ошибки что объект let1 и его данные не были найдены
class let
{
public:
int let_x, let_y;
};
void setup()
{
srand(time(NULL));
let let1;
let1.let_x = rand() % 40 + 15;
let1.let_y = rand() % 9;
if (let1.let_x > 40)
{
let1.let_x -= 20;
}
let let2;
let2.let_x = rand() % 40 + 15;
let2.let_y = rand() % 9;
if (let2.let_x > 40)
{
let2.let_x -= 20;
}
let let3;
let3.let_x = rand() % 40 + 15;
let3.let_y = rand() % 9;
if (let3.let_x > 40)
{
let3.let_x -= 20;
}
let let4;
let4.let_x = rand() % 40 + 15;
let4.let_y = rand() % 9;
if (let4.let_x > 40)
{
let4.let_x -= 20;
}
let let5;
let5.let_x = 0;
let5.let_y = 0;
system("color F4");
dir = STOP;
//game_condition = true;
hero_x = 0, hero_y = 5;
//let_x = 0, let_y = 0;
}
void graphiс()
{
system("cls");
for (int i = 0; i < max_y; i++)
{
for (int j = 0; j < max_x; j++)
{
if (i == hero_y && j == hero_x)
{
cout << "|";
}
if (i == let1.let_y && j == let1.let_x)
{
cout << "#";
++let1;
}
cout << " ";
}
if (i > max_y)
{
break;
}
cout << "\n";
}
system("cls");
} ```
Ответы (1 шт):
Автор решения: Miracle-
→ Ссылка
Немного странный у вас код. Но, если отвечать на поставленный вопрос, то:
void setup(){
//operation
graphic(let1);//передаем в ф-цию,условно let1
}
А в функции graphic():
void graphic(let& data){
//operation
}