문제

I have just started writing simple RPG game in C++. There will be a class (schema, not code)

class creature
    string name;
    int hp, strength...

There will also be quantity of them. But if I want to create two groups of same type creature, example: ('a', 100, 10)', it would be wasting of time and memory to make them separately, writing name and all other parameters two times, with only quantity being different. Do you know any method to implement quantity of creatures stacks, without necessity to repeat data?

Because I have just started working, I will be trying to do something and tell you about results.

도움이 되었습니까?

해결책

How about wrapping it in a class that represents quantity as well? What I mean is

class CreatureGroup {
    Creature creature;
    int quantity;
};
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top