I'm sorry because I don't konw how to make my in code in an box like others, it's my first to log in this forum.
here's my problem:
I wrote a RPG CMD program, the attack function can let the player run or attack.
but i want to change this to multiple enemy(player can meet several enemy), I don't know how, I just konw to change the parameter as an array, anyone can help me ? (Player and Monster are classes)
As for your problem, you can pass an array to a function in the form of a pointer:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
void func( Monster* monsters, int nummonsters )
// can treat 'monsters' as an array:
monsters.whatever = whatever;
player.whatever += monsters.whatever;
func( anarrayofmonsters, 10 ); // give it the array, and tell it how many elements it as
bool Player::attack(Monster monster), what should I do?
You should do exactly that. In a parameter listMonster* monster and Monster monster are identical:
1 2 3 4 5 6 7 8 9 10
bool Player::attack(Monster monster, int numberofmonsters)
// then when you call it:
Monster my_array_of_monsters; // 10 monsters
player.attack( my_array_of_monsters, 10 ); // give it the array, and tell it how many monsters are in the array