-
June 23rd, 2013, 05:47 PM
#1
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.
-
June 24th, 2013, 05:41 AM
#2
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 ...
Last edited by juanpast; June 24th, 2013 at 05:44 AM.
-
June 24th, 2013, 10:05 AM
#3
Re: Struct at the inside of class
Thank you, this is helpfull and simple
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 ...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|