• Advertisement

Archived

This topic is now archived and is closed to further replies.

Need help on a Design problem with a class

This topic is 5299 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#include <string>
using std::string;

struct ScoreInfo
{
    string name;
    int score;
};

class Highscore
{
private:
    ScoreInfo[10] scores;
    string path;

public:
    HighScore(string filename);
    ~Highscore();

    void Draw();
    int EnterScore(ScoreInfo score);
};
Right now ScoreInfo is hardcoded into the class. I want to be able to use different types of ScoreInfo''s without having to rewrite a lot of code, I was thinking of making Draw and EnterScore virtual and in a base class define those methods. But a friend said just make the methods templated and the private Variable scores a templated arguement. I can''t really see the best design I should go with.

Share this post


Link to post
Share on other sites
Advertisement
So, what are you trying to accomplish? Have different scores like HighScore, LowScore, AverageScore, etc.?

The question you should ask yourself when deciding between templates and polymorphism is if you''ll need runtime-typing (i.e. do you need to be able to have functionality that doesn''t know or doesn''t care what type of score it''s using) or static-typing (you''ll know what type of score you''re working with in your app at all times at compile time). If it''s the former, you need inheritance and polymorphism. If it''s the latter, you can use templates.

Share this post


Link to post
Share on other sites

  • Advertisement