trying to pass a array of a class
well i have one solution to my code right now but i would prefer to keep the main function simplier
Code:
#include <string>
#include <iostream>
using namespace std;
class monster
{
public:
int m_hps;
};
void displayMonsterHealth(monster &mon);
int main()
{
monster mon[4];
mon[0].m_hps = 23;
mon[1].m_hps = 12;
mon[2].m_hps = 31;
mon[3].m_hps = 1;
for( int i = 0; i < 4; ++i)
displayMonsterHealth(mon[i]); // this works to display the information from class
// monster but i would prefer......
system("pause");
return 0;
}
void displayMonsterHealth(monster &mon)
{
cout << mon.m_hps << endl; // to be able manage the same thing with the for(int i = 0; i < 4; ++i)
} // here and leave the Main function simple. Anyone know how i can pass the
// whole array of mon into this function then use "for" to check them.
i seen a few other posts, i think similar and one said something about vectors and iters, would like a opinion on that please