#include <iostream>
using std::cout;
using std::cin;
using std::endl;
class CPlayerStats
{
public:
// Constructor
explicit CPlayerStats(double mh = 1, double mm = 1, double ms = 1): m_health(mh), m_magic(mm), m_stamina(ms){}
// Volume Function to count volume of stats.
double Volume()
{
return m_health*m_magic*m_stamina;
}
private:
double m_health;
double m_magic;
double m_stamina;
};
int main()
{
CPlayerStats Party[5];
CPlayerStats Group(3312.0, 1455.0, 2244.0);
for(int i = 0;i < 5;i++) cout << endl << "Array current number: " << i << " . Health: " << Party[i].m_health << ", Magic: " << Party[i].m_magic << ", Stamina: " << Party[i].m_stamina << endl;
cin.get();
return 0;
}
Now it does not work because the members in class are private. If i made them public this would work. I can fix this by making a inline function inside the class and use that in the main to call for the for loop.
The problem is i dont know how to "return" the for loop result from a function or is it even possible. So please could someone explain this to me?
Public member functions can return the value of private members of a class. So you would have a function like "CPlayerStats::GetHealth()" which would return the value of the 'm_health' data for that object.