Class help
Trying to access a parent class private variables from a struct defined within the class. see code for visual.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
class pInfo
{
private:
int zphealth;
int zparmor;
int zchealth;
int zcarmor;
bool zissaved;
public:
pInfo();
void Update();
struct car {
int GetHealth() const;
void SetHealth(int num);
int GetArmor() const;
void SetArmor(int num);
}Car;
struct player {
int GetHealth() const;
void SetHealth(int num);
int GetArmor() const;
void SetArmor(int num);
}Player;
}Hades;
pInfo::pInfo(){zchealth=0;zcarmor=0;zphealth=0;zparmor=0;zissaved=false;}
void pInfo::Update()
{
zchealth = 10;
zcarmor = 20;
zphealth = 5;
zparmor = 10;
zissaved = false;
}
int pInfo::car.GetHealth() const { /* how would I access pInfo class private vars from here? */}
void pInfo::car.SetHealth(int num){ }
int pInfo::car.GetArmor() const {}
void pInfo::car.SetArmor(int num){}
int pInfo::player.GetHealth() const {}
void pInfo::player.SetHealth(int num) {}
int pInfo::player.GetArmor() const {}
void pInfo::player.SetArmor(int num) {}
|
Also note that this is nothing more than an exercise on classes prior to having to write one, which will be soon.
The syntax is
int pInfo::car::GetHealth() const { ... }
how would I access pInfo class private vars from here? |
First, you'll need an instance of the pInfo type, perhaps by supplying one in a constructor, but this is very poor design.
Topic archived. No new replies allowed.