I've been thinking a lot about generic programming lately and how it can benefit me. Though I have came across something I'm not sure of. Either I am doing it wrong which is most likely, or it's just the way to make things generic.
Let me give you some example code:
1 2 3 4 5 6 7 8 9 10 11 12
|
template <class Stats, class Skills>
class Player
{
private:
std::vector<Stats> PlayerStats; // Player stats - Health, Mana etc
std::vector<Skills> PlayerSkills; // Player skills - Slash, Fireball etc
std::string PlayerName;
public:
Player(std::string n, std::vector<Stats> stats, std::vector<Skills> skills)
: PlayerName(n), PlayerStats(stats), PlayerSkills(skills) {}
~Player() {}
};
|
Now, how does one "use" or "display" it's stats or skills?
If this was for a game engine, how do I know what variables or methods people would use in their modeled classes?
My progress so far is to use a common method, for instance:
PlayerSkills.Use()
So no matter what class a person makes to model it's statistics or skills would have to include a method called "Use" (But again, does this return a float? A string? Another class?)
I'm struggling to identify if this method is too closesly couple and not generic enough.
Something I have though about but haven't tried, is making a base class that already has the function "Use" and people derive from this and ( override? ) the Use function.
Any help would be appreciated.