Struct at the inside of class
Hello,
while writing code i got a question. For example i created a class named as unit.
Think a simple game, and the unit class will belong the units.
İf i give the preferences as private one by one, it will be irregular. For a detailed game; height, weight, race, hair preferences, eyes... Strength, dexterity, charisma, intelligence, wisdom, constution... experience, damage, armor...
and should i use struct to group them? And how to can i use struct at the inside of class as private? Can u give me examples.
Thank you.
Re: Struct at the inside of class
Hi
Code:
class CAtributes {
public:
CAtributes();
~CAtributes();
int age, height, weight;
};
class CPerson {
private:
CAtributes atributes;
public:
CPerson();
~CPerson();
int get_age {
return atributes.age;
}
int get_height {
return atributes.height;
}
int get_weight {
return atributes.weight;
}
void set_age(int age) {
atributes.age = age;
}
void set_height(int height) {
atributes.height = height;
}
void set_weight(int weight) {
atributes.weight = weight;
}
};
Best regards.
EDIT: you can use, struct unless class for atributes ...
Re: Struct at the inside of class
Thank you, this is helpfull and simple :)
Quote:
Originally Posted by
juanpast
Hi
Code:
class CAtributes {
public:
CAtributes();
~CAtributes();
int age, height, weight;
};
class CPerson {
private:
CAtributes atributes;
public:
CPerson();
~CPerson();
int get_age {
return atributes.age;
}
int get_height {
return atributes.height;
}
int get_weight {
return atributes.weight;
}
void set_age(int age) {
atributes.age = age;
}
void set_height(int height) {
atributes.height = height;
}
void set_weight(int weight) {
atributes.weight = weight;
}
};
Best regards.
EDIT: you can use, struct unless class for atributes ...